11

I'd like to be able to test the BroadcastReceiver for MY_PACKAGE_REPLACED.

Can I accomplish this with an adb command?

Does the emulator accomplish this when I launch an app from the IDE (Android studio)?

dols
  • 733
  • 8
  • 16
  • I published an update to my app and, after the upgrade, the code for this handler was executed. in case anyone was wondering when precisely the code is run. – dols Dec 02 '14 at 06:19

2 Answers2

15

am broadcast -a android.intent.action.MY_PACKAGE_REPLACED

Alex P.
  • 30,437
  • 17
  • 118
  • 169
  • does this send the intent to all apps? or just my app under test – dols Dec 01 '14 at 22:15
  • 1
    it sends it to all apps by default. you can specify the receiver using `-n` parameter – Alex P. Dec 01 '14 at 22:33
  • 3
    ok, yes, that's it. for the -n option, I specified / where is the 'package' attribute from the manifest XML element, and is the 'android:name' attribute from the receiver element that handles that intent. still unclear on which MY_PACKAGE_REPLACED code is executed: the old app code and the new app code that was replaced – dols Dec 01 '14 at 22:39
  • 9
    I want to warn people, be careful when using this command. I ran this on my phone and it ended up being stuck in demo mode because this calls the intent on ALL apps. Use the `-n` parameter to avoid this as @AlexP. mentioned. – Prem Mar 09 '15 at 16:08
  • 7
    The full command is `adb shell am broadcast -a android.intent.action.MY_PACKAGE_REPLACED` – cprcrack Oct 01 '17 at 18:11
  • @Prem What ist the "demo mode" of an Android phone? Why should it be a problem if any app "thinks" it was updated? It should just do what it does after an update if it's supoosed to do something then. I don't understand the problem. – The incredible Jan Nov 22 '18 at 08:57
4

Unfortunately the previously proposed solution is not supported on Android 7.0+ because only the system is allowed to broadcast it.

However the intent can be stimulated by adb install -r command when side loading the app.

I don't take credit for this answer as it has been submitted in another thread.

nesluk
  • 41
  • 2