监听开机,程序安装,卸载,唤醒

来源:互联网 发布:天刀捏脸数据导出 编辑:程序博客网 时间:2024/06/06 13:21
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>

 

0 0
原创粉丝点击