zoukankan      html  css  js  c++  java
  • 安卓开发之应用的卸载与安装(广播接收者案例)

    <?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());
            }
        }
    }
  • 相关阅读:
    HDU4452——模拟——Running Rabbits
    URAL1711——模拟——Code Names
    URAL1721——匈牙利算法——Two Sides of the Same Coin
    Codeforces Round #FF (Div. 1)——A贪心——DZY Loves Sequences
    Codeforces Round #326 (Div. 2)
    URAL 7077 Little Zu Chongzhi's Triangles(14广州I)
    Codeforces Round #325 (Div. 2)
    位运算 UEST 84 Binary Operations
    LCA UESTC 92 Journey
    Codeforces Round #324 (Div. 2)
  • 原文地址:https://www.cnblogs.com/duxie/p/11026801.html
Copyright © 2011-2022 走看看