Android利用系统广播---监听应用程序安装和卸载
来源:互联网 发布:透视软件 编辑:程序博客网 时间:2024/04/26 19:04
第一、 新建监听类:BootReceiver继承BroadcastReceiver
【科学上网软件点击下载(能上youtube、facebook,享受google服务)】
- public class BootReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- //接收广播:系统启动完成后运行程序
- if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
- Intent newIntent = new Intent(context, WatchInstall.class);
- newIntent.setAction("android.intent.action.MAIN"); newIntent.addCategory("android.intent.category.LAUNCHER"); newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(newIntent);
- }
- //接收广播:设备上新安装了一个应用程序包后自动启动新安装应用程序。
- if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
- String packageName = intent.getDataString().substring(8);
- System.out.println("---------------" + packageName);
- Intent newIntent = new Intent();
- newIntent.setClassName(packageName,packageName+ .MainActivity");
- newIntent.setAction("android.intent.action.MAIN"); newIntent.addCategory("android.intent.category.LAUNCHER"); newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(newIntent);
- }
- //接收广播:设备上删除了一个应用程序包。
- if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) {
- System.out.println("********************************");
- DatabaseHelper dbhelper = new DatabaseHelper();
- dbhelper.executeSql("delete from users");
- }
- }
public class BootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //接收广播:系统启动完成后运行程序 if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { Intent newIntent = new Intent(context, WatchInstall.class);newIntent.setAction("android.intent.action.MAIN"); newIntent.addCategory("android.intent.category.LAUNCHER"); newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(newIntent); } //接收广播:设备上新安装了一个应用程序包后自动启动新安装应用程序。 if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) { String packageName = intent.getDataString().substring(8); System.out.println("---------------" + packageName); Intent newIntent = new Intent(); newIntent.setClassName(packageName,packageName+ .MainActivity");newIntent.setAction("android.intent.action.MAIN"); newIntent.addCategory("android.intent.category.LAUNCHER"); newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(newIntent); } //接收广播:设备上删除了一个应用程序包。 if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) { System.out.println("********************************"); DatabaseHelper dbhelper = new DatabaseHelper(); dbhelper.executeSql("delete from users"); } }
第二、 修改AndroidManifest.xml配置文件
- <?xml version="1.0" encoding="UTF-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="org.me.watchinstall">
- <application>
- <receiver android:name=".BootReceiver"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED"/>
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.PACKAGE_ADDED" />
- <action android:name="android.intent.action.PACKAGE_REMOVED" />
- <data android:scheme="package" />
- <!-- 注意!! 这句必须要加,否则接收不到BroadCast -->
- </intent-filter>
- </receiver>
- <activity android:name=".WatchInstall" android:label="WatchInstall">
- <intent-filter>
- <action android:name="android.intent.action.MAIN"/>
- <category android:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
- </activity>
- </application>
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="android.permission.RESTART_PACKAGES"/>
- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
- </manifest>
- Android利用系统广播---监听应用程序安装和卸载
- Android利用系统广播---监听应用程序安装和卸载
- Android利用系统广播---监听应用程序安装和卸载
- Android利用系统广播---监听应用程序安装和卸载
- Android利用系统广播---监听应用程序安装和卸载
- Android利用系统广播---监听应用程序安装和卸载
- Android利用系统广播---监听应用程序安装和卸载
- Android利用系统广播---监听应用程序安装和卸载
- Android利用系统广播---监听应用程序安装和卸载
- Android利用系统广播---监听应用程序安装和卸载
- Android利用系统广播---监听应用程序安装和卸载
- Android利用系统广播---监听应用程序安装和卸载
- Android利用系统广播---监听应用程序安装和卸载
- Android利用系统广播---监听应用程序安装和卸载
- Android利用系统广播---监听应用程序安装和卸载
- Android利用广播监听设备安装和卸载应用程序
- Android利用广播---监听应用程序安装和卸载,删除安装包
- Android监听应用程序安装和卸载
- HibernateLab--双向一对多
- 转个 小笑话
- stringbuilder stringbuffer
- HibernateLab--多对多
- C++ Heap corruption detected
- Android利用系统广播---监听应用程序安装和卸载
- 第十五章 AJAX JQuery
- Applet的数字签名
- 面试题:火车运煤问题
- SQL触发器
- jquery图片提示效果
- ubuntu下搭建android开发环境
- 【转】 一个使用WordNet比较词语相似度的Java包——JWS(Java WordNet Similarity)
- 为uThreadPool增加线程池等待功能