android - 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>
引导接收器
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 相混淆,遗憾的是,我浪费了几个小时来弄清楚这一点!
推荐阅读
- git - 更改所有本地存储库的 Git URL
- java - 让 LocalDate 在 Javafx 的 Tableview 中显示
- jquery - jQuery getJSON 获取数据
- docker - Jenkins 声明式管道与来自 SCM 的 Docker/Dockerfile 代理
- java - 在spring boot java中测试一个采用模型参数的函数
- google-apps-script - 无法让这个“标记未答复的电子邮件”脚本工作
- mysql - mysql vs redis 用于对话(聊天)?
- swift - Swift MetalKit 未知返回类型 MTKMesh.newMeshes
- powershell - 在 Powershell 中使用字符串中的 csv 记录
- c# - 重放 BufferedWaveProvider