当我的应用程序更新或树脂安装时,我正在使用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>
Run Code Online (Sandbox Code Playgroud)
码:
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
}
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码很简单,实际上我使用了其他事件,比如BOOT_COMPLETED和其他事件,它们可以工作但ACTION_MY_PACKAGE_REPLACED.谢谢.