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();
    }
     }
     
     
  • 相关阅读:
    布局的诡异bug合集+解决方法(更新中)
    java并发:CopyOnWriteArrayList简单理解
    java集合: LinkedList源码浅析
    Idea设置类注释模板
    jquery使用FormData提交数据
    postman发送json请求
    消息队列的简单理解
    如何设计一个消息队列?
    SpringBoot配置logback
    linux下安装kafka
  • 原文地址:https://www.cnblogs.com/SoulCode/p/6393363.html
Copyright © 2011-2022 走看看