【发布时间】:2021-12-28 10:05:40
【问题描述】:
我想找到我的应用程序的升级。所以我一直在使用这个代码来找到它 PACKAGE_REPLACED,但突然我无法接收到我的应用程序包替换的事件。
我改成了 MY_PACKAGE_REPLACED。还是同样的问题。
分析了一些堆栈溢出问题。没有运气。尝试了所有答案。
我的目标sdk版本是30:
清单代码:
<receiver android:name=".Receiver" android:enabled="true" android:debuggable="true" android:exported="true"
tools:ignore="HardcodedDebugMode">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
收货人代码
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d(TAG, "action = " + action);
if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
Log.d(TAG, "BOOT COMPLETED, Ping start...");
} else if (Intent.ACTION_PACKAGE_REPLACED.equals(action)) {
Log.d(TAG, "PACKAGE REPLACED, upgrade ping...");
} else {
//default action is network changed
Log.d(TAG, "network status changed...");
}
}
【问题讨论】:
-
"突然我无法接收事件" - 你是在暗示你之前有工作代码吗?
-
@Pawel 对不起,以前我使用这个事件“android.intent.action.PACKAGE_REPLACED”现在它失败了。我更改为 MY_PACKAGE_REPLACED。但仍然未能获得事件。
-
更新了我的问题。 @Pawel
-
我不明白你的句子。这个接收器有没有工作过?
-
是的。 Action_PACKAGE_REPLACED 正在工作,但现在不行。 @Pawel
标签: android android-intent android-sdk-tools target-sdk