• 安卓开发之应用的卸载与安装(广播接收者案例)


    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.lidaochen.test001">
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <receiver android:name=".AppStateReceiver">
                <intent-filter>
                    <action android:name="android.intent.action.PACKAGE_INSTALL"></action>
                    <action android:name="android.intent.action.PACKAGE_ADDED"></action>
                    <action android:name="android.intent.action.PACKAGE_REMOVED"></action>
                    <!-- 想让action事件生效 还需要配置一个data -->
                    <data android:scheme="package"></data>
                </intent-filter>
            </receiver>
        </application>
    
    </manifest>
    package com.lidaochen.test001;
    
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.widget.Toast;
    
    public class AppStateReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            // 获取当前广播事件的类型
            String action = intent.getAction();
            if("android.intent.action.PACKAGE_INSTALL".equals(action))
            {
                System.out.println("应用安装了111");
            }
            // 最后执行的是这个
            else if("android.intent.action.PACKAGE_ADDED".equals(action))
            {
                System.out.println("应用安装了222");
            }
            else if("android.intent.action.PACKAGE_REMOVED".equals(action))
            {
                System.out.println("应用卸载了222" + intent.getData());
            }
        }
    }
  • 相关阅读:
    deferred 对象
    JVM--------3
    JVM类加载机制————2
    JVM加载的初始化类
    补充==的使用和equals的区别
    MyBatis_SelectKey使用oracle 序列插入主键
    MySql_ procedure
    mysql function
    jsonp _____跨域请求实现
    shell(shell变量、条件表达式、流程控制)
  • 原文地址:https://www.cnblogs.com/duxie/p/11026801.html
Copyright © 2020-2023  润新知