Android应用卸载广播监听

1.今天在项目中遇到一个小问题,感觉挺好玩的,记录下:
在进行应用卸载弹窗时,通过接收Intent.ACTION_PACKAGE_REMOVED 广播,进行判断处理,即可完成应用的卸载监听,可是在实际使用中,发现应用在进行覆盖安装时,也会接收到这个广播,而且比Intent.ACTION_PACKAGE_REPLACED靠前,这就尴尬了
后来通过查询一些资料发现,原来应用在覆盖安装时是会接收到三个广播的,先后顺序如下:
  • ACTION_PACKAGE_REMOVED 
  • ACTION_PACKAGE_ADDED 
  • ACTION_PACKAGE_REPLACED 
为了解决此问题,需要在接收到的remove广播中检测一个  EXTRA_REPLACING  flag值,如果为true,则未覆盖安装;
To tell that that an  ACTION_PACKAGE_REMOVED  or  ACTION_PACKAGE_ADDED  intent is received as the result of a package being replaced (instead of plain add or remove), check the  EXTRA_REPLACING  flag: 
boolean replacing = intent . getBooleanExtra ( Intent . EXTRA_REPLACING , false );

猜你喜欢

转载自blog.csdn.net/zxcofuestc/article/details/72627972
今日推荐