Bink
Bink

Reputation: 2171

android.intent.action.MY_PACKAGE_REPLACED Not Working

I can't seem to catch this and I also can't see it being sent in Logcat. From reviewing ACTION_MY_PACKAGE_REPLACED not received, it appears MY_PACKAGE_REPLACED should be all I need for API22.

What am I missing?

Thank you.

Snippet from AndroidManifest.xml

    <receiver
        android:name=".BootReceiver"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
        </intent-filter>
    </receiver>

BootReceiver

class BootReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        if (intent.action == "android.intent.action.BOOT_COMPLETED" ||
                intent.action == "android.intent.action.MY_PACKAGE_REPLACED") {
            Log.d(TAG, "Caught BOOT_COMPLETED or PACKAGE_REPLACED action!")
            GlobalScope.launch(Dispatchers.IO) {
                ...
            }
        }
    }
}

Upvotes: 7

Views: 4646

Answers (1)

Bink
Bink

Reputation: 2171

Upon further investigation, this works properly if Android Studio (AS) is removed from the picture; use it to build the APK and, perhaps, view Logcat, but that’s it. If I only install/replace the app from the command line/Terminal, and do not Run app and related from AS, this works as intended. In my case, since I frequently install/Run from AS, I had to do the following TWICE and android.intent.action.MY_PACKAGE_REPLACED was caught the SECOND time:

adb -s emulator-5554 install -r app-debug.apk

I repeat, running the app from Android Studio, in this regard, severally messes with android.intent.action.MY_PACKAGE_REPLACED and I, sadly, lost a couple of hours figuring this out!

Upvotes: 15

Related Questions