zoukankan      html  css  js  c++  java
  • 监听开机,程序安装,卸载,唤醒

    public class PushReceiver extends BroadcastReceiver {
    
    
        @Override
        public void onReceive(Context context, Intent intent) {
            if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){
                System.out.println("手机开机了...bootComplete!");
            }else
            if(Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())){
                System.out.println("新安装了应用程序....pakageAdded!");
            }else
            if(Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())){
                System.out.println("应用程序被卸载了....pakageRemoved!");
            }else
            if(Intent.ACTION_USER_PRESENT.equals(intent.getAction())){
                System.out.println("手机被唤醒了.....userPresent");
                Intent service = new Intent();
                service.setAction("com.xxx.service.PushService");
                service.setClass(context, PushService.class);
                context.startService(service);
            }
            
        }
    }

    Mainfest中注册receiver:

    <!-- push receiver -->
            <receiver android:name=".receiver.PushReceiver">
            <intent-filter>
                <!-- 手机开机 -->
                <action android:name="android.intent.action.BOOT_COMPLETED"></action>
                <!-- 手机唤醒解锁 -->
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
            <intent-filter>
                <!-- 程序包安装与卸载 -->
                <action android:name="android.intent.action.PACKAGE_ADDED"></action>
                <action android:name="android.intent.action.PACKAGE_REMOVED"></action>
                <data android:scheme="package"></data>
            </intent-filter>
            </receiver>
  • 相关阅读:
    C++学习总结 复习篇2
    C++ 学习总结 复习篇
    Git 安装与使用
    前两周工作总结
    [bzoj1033] [ZJOI2008]杀蚂蚁antbuster
    [bzoj1031] [JSOI2007]字符加密Cipher
    [bzoj1030] [JSOI2007]文本生成器
    [bzoj1029] [JSOI2007]建筑抢修
    [bzoj1028] [JSOI2007]麻将
    [bzoj1026] [SCOI2009]windy数
  • 原文地址:https://www.cnblogs.com/qinghuaideren/p/3148720.html
Copyright © 2011-2022 走看看