android.intent.action.MY_PACKAGE_REPLACED 不工作

2024-03-11

我似乎无法理解这一点,也看不到它在 Logcat 中发送。从审查未收到 ACTION_MY_PACKAGE_REPLACED https://stackoverflow.com/questions/12666734/action-my-package-replaced-not-received,看来 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>

引导接收器

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) {
                ...
            }
        }
    }
}

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

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

android.intent.action.MY_PACKAGE_REPLACED 不工作 的相关文章

随机推荐