My use case is that when a new version of the application is available, I display the update information. However, after the user updates the app, it closes and does not restart automatically. The user has to manually navigate to the app and click the icon to launch it.
I used Broadcast Receiver using the "MY_PACKAGE_REPLACED" in the manifest but it is not working.
And i am getting the error as
*BroadcastQueue: Background execution not allowed:
In manifest.xml
<receiver
android:name=".AppInstallationReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
Receiver
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
Log.e(TAG, "Package replaced, starting the service");
Intent serviceIntent = new Intent(context, InstallationCheckerService.class);
ContextCompat.startForegroundService(context, serviceIntent);
}
}
Error:
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.application.dev.android flg=0x4000010 (has extras) } to com.android.packageinstaller/.PackageInstalledReceiver
My use case is that when a new version of the application is available, I display the update information. However, after the user updates the app, it closes and does not restart automatically. The user has to manually navigate to the app and click the icon to launch it.
I used Broadcast Receiver using the "MY_PACKAGE_REPLACED" in the manifest but it is not working.
And i am getting the error as
*BroadcastQueue: Background execution not allowed:
In manifest.xml
<receiver
android:name=".AppInstallationReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
Receiver
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
Log.e(TAG, "Package replaced, starting the service");
Intent serviceIntent = new Intent(context, InstallationCheckerService.class);
ContextCompat.startForegroundService(context, serviceIntent);
}
}
Error:
Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.application.dev.android flg=0x4000010 (has extras) } to com.android.packageinstaller/.PackageInstalledReceiver
Add the lines mentioned below in your AndroidManifest.xml
file:
<receiver android:name=".UpdateReceiver">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
</intent-filter>
</receiver>
Create the broadcast receiver class and in the onReceive()
method add the lines below:
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
Intent restartIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
if (restartIntent != null) {
restartIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(restartIntent);
}
}
}
Try this, it should work.