zoukankan      html  css  js  c++  java
  • 应用的安装卸载更新监听

    第一步,创建一个广播接收者,

     AppsReceiver extends BroadcastReceiver
    第二步,在AndroidManifest.xml配置文件中注册广播接收者与配置应用状态发生时对应的Action:
     <receiver android:name="com.itheima.appslistener.AppsReceiver">
                <intent-filter >
                    <action android:name="android.intent.action.PACKAGE_ADDED"/>
                    <action android:name="android.intent.action.PACKAGE_REPLACED"/>
                    <action android:name="android.intent.action.PACKAGE_REMOVED"/>
                    <data android:scheme="package"/>
                </intent-filter>
            </receiver>
    第三步,重写广播接受者中OnReceiver方法:
    public void onReceive(Context context, Intent intent) {
    //判断收到的是什么广播
    String action = intent.getAction();
    //获取安装更新卸载的是什么应用
    Uri uri = intent.getData();
    if(Intent.ACTION_PACKAGE_ADDED.equals(action)){
    Toast.makeText(context, uri + "被安装了", 0).show();
    }
    else if(Intent.ACTION_PACKAGE_REMOVED.equals(action)){
    Toast.makeText(context, uri + "被删除了", 0).show();
    }
    else if(Intent.ACTION_PACKAGE_REPLACED.equals(action)){
    Toast.makeText(context, uri + "被更新了", 0).show();
    }
     }
     
     
  • 相关阅读:
    微信小程序@bindgetuserinfo @bindgetphonenumber
    报错总结
    前端面试题
    关于vue ssr next服务端渲染
    【012】JavaSE面试题(十二):多线程(2)
    【011】JavaSE面试题(十一):多线程(1)
    [010]
    [009]
    [008]
    添加Lombok插件后调用Setter或Getter方法IDEA编译错误
  • 原文地址:https://www.cnblogs.com/SoulCode/p/6393363.html
Copyright © 2011-2022 走看看