android.intent.action.MY_PACKAGE_REPLACED 不工作

Bin*_*ink 6 android intentfilter broadcastreceiver android-intent kotlin

我似乎无法理解这一点,也看不到它在 Logcat 中发送。通过审查未收到 ACTION_MY_PACKAGE_REPLACED,看来 MY_PACKAGE_REPLACED 应该是我对 API22 所需的全部。

我缺少什么?

谢谢。

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>
Run Code Online (Sandbox Code Playgroud)

引导接收器

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) {
                ...
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Bin*_*ink 13

经进一步调查,如果从图片中删除 Android Studio (AS),则可以正常工作;使用它来构建 APK,也许还可以查看 Logcat,但 \xe2\x80\x99 就是它。如果我只从命令行/终端安装/替换应用程序,并且不从 AS 运行应用程序和相关应用程序,则这将按预期工作。就我而言,由于我经常从 AS 安装/运行,所以我必须执行以下两次操作,并且 android.intent.action.MY_PACKAGE_REPLACED 第二次被捕获:

\n
adb -s emulator-5554 install -r app-debug.apk\n
Run Code Online (Sandbox Code Playgroud)\n

我重复一遍,从 Android Studio 运行该应用程序,在这方面,分别与 android.intent.action.MY_PACKAGE_REPLACED 混淆,遗憾的是,我花了几个小时来解决这个问题!

\n