Android apk 安装、清理数据、强行停止、卸载监听
不废话,上代码
<receiver android:name="com.test.Receiver" android:enabled="true"> <intent-filter > <action android:name="android.intent.action.PACKAGE_ADDED"/> <action android:name="android.intent.action.PACKAGE_REMOVED"/> <action android:name="android.intent.action.PACKAGE_CHANGED"/> <action android:name="android.intent.action.PACKAGE_DATA_CLEARED"/> <action android:name="android.intent.action.PACKAGE_FIRST_LAUNCH"/> <action android:name="android.intent.action.PACKAGE_FULLY_REMOVED"/> <action android:name="android.intent.action.PACKAGE_REPLACED"/> <action android:name="android.intent.action.PACKAGE_RESTARTED"/> <data android:scheme="package"></data> </intent-filter> </receiver>
以下是各个情况下,发送的广播
1\安装
android.intent.action.PACKAGE_ADDED
2覆盖安装
android.intent.action.PACKAGE_REMOVED
android.intent.action.PACKAGE_ADDED
android.intent.action.PACKAGE_REPLACED
3\清理数据
android.intent.action.PACKAGE_RESTARTED
android.intent.action.PACKAGE_DATA_CLEARED
4\强行停止
Action: android.intent.action.PACKAGE_RESTARTED
5\卸载
android.intent.action.PACKAGE_REMOVED
android.intent.action.PACKAGE_FULLY_REMOVED
在广播中得到包名的方法
ComponentName cn = intent.getComponent() ; Uri uu= intent.getData() ; String name = uu.getSchemeSpecificPart();
得到apk(未安装)相关信息:
public static void getAPKPackageInfo(Context context,String apkPath){ PackageManager packageManager = context.getPackageManager(); PackageInfo info = packageManager.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES); if(info != null){ ApplicationInfo appInfo = info.applicationInfo; String appName = packageManager.getApplicationLabel(appInfo).toString(); String packageName = appInfo.packageName; //得到安装包名称 String version=info.versionName; //得到版本信息 Drawable icon = packageManager.getApplicationIcon(appInfo);//得到图标信息 } }
时间: 2024-09-29 09:43:06