android.intent.action.MY_PACKAGE_REPLACED 不工作 [英] android.intent.action.MY_PACKAGE_REPLACED Not Working
问题描述
我似乎无法捕捉到这个,我也看不到它在 Logcat 中发送.通过查看未收到ACTION_MY_PACKAGE_REPLACED,看来MY_PACKAGE_REPLACED 应该是API22 所需要的.
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.
我错过了什么?
谢谢.
来自 AndroidManifest.xml 的片段
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>
启动接收器
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:
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
我再说一遍,在这方面,从 Android Studio 运行应用程序时,多次与 android.intent.action.MY_PACKAGE_REPLACED 混淆,遗憾的是,我花了几个小时才弄明白!
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!
这篇关于android.intent.action.MY_PACKAGE_REPLACED 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!