Open my Android program after update

I am using https://stackoverflow.com/a/312929/ for updating my Android program, but after updating my program it will be closed, so I want to open it again after the update process is complete, how can I do it?

I used this class

package services; public class PackageChangeReceiver extends BroadcastReceiver { @Override public void onReceive(Context ctx, Intent intent) { Uri data = intent.getData(); boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); Intent intent1 = new Intent(ctx, service.class); ctx.startService(intent1); Log.d("service", "Action: " + intent.getAction()); Log.d("service", "The DATA: " + data); } } 

and this mainfest

  <receiver android:name="services.PackageChangeReceiver" > <intent-filter> <action android:name="android.intent.action.PACKAGE_REMOVED" /> <action android:name="android.intent.action.PACKAGE_REPLACED" /> <action android:name="android.intent.action.PACKAGE_ADDED" /> <data android:scheme="package" /> </intent-filter> </receiver> 

but I still get the intention after starting the application manually

+6
source share
3 answers

a) See android.intent.action.PACKAGE_REPLACED .

b) I believe that if your application has a sticky service, this service restarts after updating the package.

+3
source

Maybe AlarmManager can help? You can configure the task to start the Activity of your application, for example, 40 seconds after your apk has loaded and the user clicked to install it.

+1
source

For API level 12 & above

Just register the broadcast receiver to receive the call only after updating the application package .

 public class PackageUpdateReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //get the launch activity or any activity you want to open Intent i = getBaseContext().getPackageManager(). getLaunchIntentForPackage(getBaseContext().getPackageName()); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } 

Be sure to register the broadcast receiver in the manifest!

  <receiver android:name=".receivers.PackageUpdateReceiver"> <intent-filter> <action android:name="android.intent.action.MY_PACKAGE_REPLACED" /> </intent-filter> </receiver> 

Now for the API level & lt; 12

You must register to receive the universal package update recipient by replacing the action name in the manifest as shown below.

 MY_PACKAGE_REPLACED with PACKAGE_REPLACED 

And in the onReceive () method of BroadcastReceiver, check if it is the name of your application package,

 if (intent.getDataString().contains("com.your.app")){ ... } 
0
source

All Articles