如何解决android.intent.action.MY_PACKAGE_REPLACED无法正常工作
我似乎看不到它,也看不到它在Logcat中发送。通过查看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>
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) {
...
}
}
}
}
解决方法
进一步调查后,如果删除了Android Studio(AS)图片,则此方法可以正常工作;用它来构建APK,也许可以查看Logcat,仅此而已。如果我仅从命令行/终端安装/替换应用程序,而没有从AS运行应用程序和相关应用程序,则这将按预期工作。就我而言,由于我经常从AS安装/运行,因此我必须执行以下两次TWICE,并且android.intent.action.MY_PACKAGE_REPLACED被捕获了第二时间:
adb -s emulator-5554 install -r app-debug.apk
在这方面,我重复一遍,从Android Studio运行该应用程序,几次与android.intent.action.MY_PACKAGE_REPLACED混为一谈,可悲的是,我花了几个小时才弄清楚这一点!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。