I use https://stackoverflow.com/a/14353076/1327384 to update my android program , but after updating my program it will be closed so I want to reopen it after completing the update process , how can I do that ?
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 receive the intent after I start the app manually
a) Take a look at android.intent.action.PACKAGE_REPLACED.
b) I believe if your app has a sticky service then this service is restarted after package update.
May be AlarmManager can help? You can set task to start Activity of your app for example in 40 seconds after your apk downloaded and user clicked to install it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With