3

I've already tried several things and now I've put all actions into one receiver:

  <receiver android:name=".ReceiverClass">
        <intent-filter android:priority="1000">
            <action android:name="android.intent.action.PACKAGE_REPLACED" />
            <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
            <action android:name="android.intent.action.PACKAGE_INSTALL"/>
            <action android:name="android.intent.action.PACKAGE_ADDED"/>
            <action android:name="android.intent.action.PACKAGE_REMOVED"/>
            <data android:scheme="package"/>
        </intent-filter>
    </receiver>

This is my Receiver class

public class ReceiverClass extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {


    if (Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())) {
        Toast.makeText(context, "1", Toast.LENGTH_LONG).show();
    }

    if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
        Toast.makeText(context, "2", Toast.LENGTH_LONG).show();
        System.out.println("test");
    }

    if (Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())) {
        Toast.makeText(context, "3", Toast.LENGTH_LONG).show();
        System.out.println("test");
    }

    if (Intent.ACTION_PACKAGE_INSTALL.equals(intent.getAction())) {
        Toast.makeText(context, "4", Toast.LENGTH_LONG).show();
        System.out.println("test");
    }

    if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
        Toast.makeText(context, "5", Toast.LENGTH_LONG).show();
        System.out.println("test");
    }



    if (Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())) {
        Toast.makeText(context, "6", Toast.LENGTH_LONG).show();
        System.out.println("test");
    }
    }
}

None of the Toasts get displayed, when I manuall install a new signed APK. Is there something I am missing as the only really replied posts are from 2015 or even earlier. Time flies.

TesterOlaf
  • 41
  • 1
  • 6

1 Answers1

2

ACTION_PACAKGE_INSTALL has never been used, according to the documentation.

ACTION_MY_PACKAGE_REPLACED is only broadcast to you if your own app is being upgraded. You will not receive it for changes in other apps.

The other three you cannot register for in the manifest on Android 8.0+, as implicit broadcasts are banned and those actions are not on the whitelist.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for your quick reply. Even just with ACTION_MY_PACKAGE_REPLACED it doesn't work. Is there like a special way to test it as I've read here and there? – TesterOlaf May 15 '20 at 21:17
  • @TesterOlaf: "Even just with ACTION_MY_PACKAGE_REPLACED it doesn't work" -- that should work AFAIK, if you upgrade your own app. That is "broadcast" just to your app, so it is already exempt from the implicit broadcast restriction. Personally, I have not had a need to use it much, so I cannot comment on testing it. – CommonsWare May 15 '20 at 21:21
  • whats the solution for this ? – Feroz Siddiqui May 04 '21 at 14:15
  • @FerozSiddiqui: I do not know what overall problem you are trying to solve. – CommonsWare May 04 '21 at 15:31
  • @CommonsWare please help me and have a look at this issue https://stackoverflow.com/questions/67386167/android-how-to-get-a-callback-in-app-when-app-gets-autoupdate-in-google-playst – Feroz Siddiqui May 05 '21 at 05:33
  • @FerozSiddiqui: You should be able to register for `ACTION_MY_PACKAGE_REPLACED` in the manifest. – CommonsWare May 05 '21 at 12:56
  • Background execution not allowed: receiving Intent { act=android.intent.action. ACTION_MY_PACKAGE_REPLACED. I am getting this – Feroz Siddiqui May 05 '21 at 14:57
  • @FerozSiddiqui: I doubt that, since that is not the correct `Intent` action string. – CommonsWare May 05 '21 at 14:59