监听应用程序的安装、卸载

AndroidManifest.xml中注册一个静态广播,监听安装的广播
android.intent.action.PACKAGE_ADDED 监听程序卸载的广播
android.intent.action.PACKAGE_REMOVED ,在广播中一定要加上
不然就监听不到

  <receiver    android:name=".AppInstallReceiver" android:enabled="true">    <intent-filter>         <action android:name="android.intent.action.PACKAGE_ADDED" />         <action android:name="android.intent.action.PACKAGE_REMOVED" />         <data android:scheme="package" />      intent-filter>  receiver>

在java代码中,需要写一个类继承 BroadcastReceiver

  public class AppInstallReceiver extends BroadcastReceiver{    @Override    public void onReceive(Context context, Intent intent) {        String action = intent.getAction();        if(action.equals(Intent.ACTION_PACKAGE_ADDED)){          Log.d("tag","app installed ");        }else if(action.equals(Intent.ACTION_PACKAGE_REMOVED)){          Log.d("tag","app uninstalled");        }    }  }

可以通过intent获取应用的报名
String pkgName = intent.getDataString().substring(8)

更多相关文章

  1. 没有一行代码,「2020 新冠肺炎记忆」这个项目却登上了 GitHub 中
  2. Nginx系列教程(四)| 一文带你读懂Nginx的动静分离
  3. Android处理图像数据转换的各种方法
  4. Android(安卓)源代码下载
  5. Android(安卓)App启动图启动界面(Splash)的简单实现
  6. Android(安卓)Annotations(1)
  7. 【Android(安卓)开发教程】TimePicker
  8. Android(安卓)在子线程中更新UI
  9. 在 Ubuntu 下配置 Android(安卓)开发环境

随机推荐

  1. android代码实现自动关机
  2. Android中获取电池电量
  3. java android MD5加密
  4. android widget桌面时钟
  5. Android(安卓)Development Notes-2
  6. android WiFi 开关代码
  7. 自定义垂直文字view
  8. Android中GPS/Map的运用
  9. Android(安卓)弹出对话框Dialog
  10. android动态添加ImageView注意