【发布时间】:2012-10-01 01:56:48
【问题描述】:
我正在使用 ACTION_MY_PACKAGE_REPLACED 来接收我的应用程序更新或重新安装的时间。 我的问题是该事件从未被触发(我尝试了 Eclipse 和真实设备)。 我就是这样做的:
清单:
<receiver android:name=".MyEventReceiver" >
<intent-filter android:priority="1000" >
<action android:name="android.intent.action.ACTION_MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
代码:
public class MyEventReceiver extends BroadcastReceiver
{
@Override public void onReceive(Context context, Intent intent)
{
if ("android.intent.action.ACTION_MY_PACKAGE_REPLACED".equals(intent.getAction()))
{ //Restart services
}
}
}
这段代码很简单,实际上我使用了其他事件,例如 BOOT_COMPLETED 和其他事件,它们可以工作,但 ACTION_MY_PACKAGE_REPLACED。 谢谢。
【问题讨论】:
-
你有两个问题。您的操作名称错误;它不应包含
ACTION_前缀。此外,MY_PACKAGE_REPLACED适用于 API 12+。