android 监听 APK 安装 与 删除等过程
来源:互联网 发布:美国电影人工智能 编辑:程序博客网 时间:2024/06/05 01:51
软件下载后的一系列动作监听:先前是通过Service监听扫描获取状态,以后用这个方法测试使用
import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.widget.Toast;public class getBroadcast extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if(Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())){ Toast.makeText(context, "有应用被添加", Toast.LENGTH_LONG).show(); } else if(Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())){ Toast.makeText(context, "有应用被删除", Toast.LENGTH_LONG).show(); } /* else if(Intent.ACTION_PACKAGE_CHANGED.equals(intent.getAction())){ Toast.makeText(context, "有应用被改变", Toast.LENGTH_LONG).show(); }*/ else if(Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())){ Toast.makeText(context, "有应用被替换", Toast.LENGTH_LONG).show(); } /* else if(Intent.ACTION_PACKAGE_RESTARTED.equals(intent.getAction())){ Toast.makeText(context, "有应用被重启", Toast.LENGTH_LONG).show(); }*/ /* else if(Intent.ACTION_PACKAGE_INSTALL.equals(intent.getAction())){ Toast.makeText(context, "有应用被安装", Toast.LENGTH_LONG).show(); }*/ } }
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="zy.Broadcast" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".Broadcast" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name="getBroadcast" android:enabled="true" > <intent-filter> <action android:name="android.intent.action.PACKAGE_ADDED"></action> <!-- <action android:name="android.intent.action.PACKAGE_CHANGED"></action>--> <action android:name="android.intent.action.PACKAGE_REMOVED"></action> <action android:name="android.intent.action.PACKAGE_REPLACED"></action> <!-- <action android:name="android.intent.action.PACKAGE_RESTARTED"></action>--> <!-- <action android:name="android.intent.action.PACKAGE_INSTALL"></action>--> <data android:scheme="package"></data> </intent-filter></receiver> </application> <uses-sdk android:minSdkVersion="7" /> </manifest>
2.代码实现添加private final BroadcastReceiver apkInstallListener = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if(Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())){ System.out.println("**************Broadcase*************"); File file = uninstallApk.get(isDeleted); System.out.println(file.toString()+"*****"); file.delete(); //System.out.println(uninstallApk.size()+"(*******"+uApks.size()); if(uninstallApk!=null&&uApks!=null) { uninstallApk.remove(isDeleted); uApks.remove(isDeleted); } //清除集合里面的值 if(uninstallApk!=null) { System.out.println("onpause******"+uninstallApk.size()); uninstallApk.clear(); } if(uApks!=null) { uApks.clear(); } System.out.println("******应用添加***"+isDeleted); Toast.makeText(context, "有应用被添加"+isDeleted, Toast.LENGTH_LONG).show(); } else if(Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())){ System.out.println("*****应用被删除"); Toast.makeText(context, "有应用被删除", Toast.LENGTH_LONG).show(); } /* else if(Intent.ACTION_PACKAGE_CHANGED.equals(intent.getAction())){ Toast.makeText(context, "有应用被改变", Toast.LENGTH_LONG).show(); }*/ else if(Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction())){ System.out.println("****应用被替换"); Toast.makeText(context, "有应用被替换", Toast.LENGTH_LONG).show(); } /* else if(Intent.ACTION_PACKAGE_RESTARTED.equals(intent.getAction())){ Toast.makeText(context, "有应用被重启", Toast.LENGTH_LONG).show(); }*/ /* else if(Intent.ACTION_PACKAGE_INSTALL.equals(intent.getAction())){ Toast.makeText(context, "有应用被安装", Toast.LENGTH_LONG).show(); }*/ } }; // 注册监听 private void registerSDCardListener(){ IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED); intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED); intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED); intentFilter.addDataScheme("package"); registerReceiver(apkInstallListener, intentFilter); } java里的调用 registerSDCardListener()@Override protected void onDestroy() { super.onDestroy(); //unregisterReceiver(apkInstallListener); }
0 0
- android 监听 APK 安装 与 删除等过程
- android 监听 APK 安装 与 删除等过程
- Android 监听apk是否安装
- Android apk安装过程
- Android APK安装过程
- Android APK安装过程
- Android APK安装过程
- Android APK安装过程
- android apk 安装过程
- 【Android】Apk安装和删除
- Android 监听apk安装替换卸载广播
- android 监听apk安装替换卸载广播
- Android apk安装监听的几个广播
- Android 监听apk安装替换卸载广播
- Android 监听apk安装替换卸载广播
- Android 监听apk安装替换卸载广播
- Android 监听apk安装替换卸载广播
- Android apk 的安装过程
- C语言--Friends and Present
- Mongodb入门——安装与配置
- android的ViewPager注意事项
- Cocos2d - x学习笔记 [2] 菜单(GUI)、场景跳转
- webserver的简单login系统
- android 监听 APK 安装 与 删除等过程
- Android学习之 Activity堆栈管理与控制
- 关键字return
- “基数排序”应用之数组中缺失的数字
- Tomcat 严重 Error, processing connection
- OJ专题(一)
- 1的个数_JAVA_南阳理工ACM100
- poj 1011 Sticks
- ios UITableView表视图(2)