skip to Main Content

I have an Android project with 2 apps.

AppA register a receiver for the actions ACTION_PACKAGE_ADDED or ACTION_PACKAGE_REPLACED from code (not in it’s Manifest).

When I install AppB from command line with adb install AppB.apk I see that the BroadcastReceiver from AppA receive a broadcast intent as expected.

When I deploy AppB directly from AndroidStudio (with launch debug button) : the BroadcastReceiver from AppA don’t receive any broadcast intent.

Is it expected ? and is there anything to do/setup in AndroidStudio to force the broadcast also when apk is deployed with the launch debug button ?

What I tried ?

Attempt 1:

I made a test with option "Always install with PackageManager" checked (in AndroidStudio launch configuration window), but it don’t help.

Attempt 2:

AndroidStudio launch configuration offer the ability to execute an external tool before launch. So I tried to explicitly broadcast the PACKAGE_ADDED action by executing : adb shell am broadcast -a android.intent.action.PACKAGE_ADDED -d com.company.app.b -t package just before launch of AppB.

Unfortunately, this generate a java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.PACKAGE_ADDED which is not really surprising as PACKAGE_ADDED is of course a protected broadcast.

2

Answers


  1. You can send a broadcast from B app with specified Action name and register it in app A

    Login or Signup to reply.
  2. can you disable instant run android studio and try. when the instant run is enabled Android studio is able to replace the dex file directly maybe that is the potential reason you are not getting ADDED or REPLACE action.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search