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


    <?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());
            }
        }
    }
  • 相关阅读:
    SharePoint 2010 Managed Metadata Columns and Metadata Navigation Settings
    SharePoint 知识整理1
    印度HCL揭秘云计算五大盈利模式
    云计算盈利模式都有什么?
    IaaS
    Salesforce
    走近云计算:解密IaaS PaaS SaaS的关系
    sasdas
    解析salesforce
    Salesforce成功的秘密
  • 原文地址:https://www.cnblogs.com/duxie/p/11026801.html
Copyright © 2020-2023  润新知