android 代码卸载指定APK小结
来源:互联网 发布:html2canvas.js api 编辑:程序博客网 时间:2024/06/09 16:38
最近做了一个东西,需要在代码中知道卸载apk,上网搜索了一下资源,具体流程如下。
1.
private static final string PACKAGE_NAME = “com.my.del.apktet”;
/**
* 获取指定包名应用列表
*/
public static List<ResolveInfo> loadAppsList(Context context, String filterStr) {
List<ResolveInfo> appList = new ArrayList<ResolveInfo>();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
appList = context.getPackageManager().queryIntentActivities(mainIntent, 0);
for (int i = appList.size() - 1; i >= 0; i--) {
String packageName = appList.get(i).activityInfo.packageName;
if (!packageName.equals(filterStr)) {
appList.remove(i);
}
}
return appList;
}
private void deleteMyApps(List<ResolveInfo> myApps) {
String packageName = myApps.get(0).activityInfo.packageName;
Uri uri = Uri.fromParts("package", packageName, null);
Intent it = new Intent(Intent.ACTION_DELETE, uri);
startActivityForResult(it, 0);
}
private void delMyTestAPK(){
List<ResolveInfo> myApps = PackageListUtil.loadAppsList(mContext, PACKAGE_NAME);
if (myApps.size() == 0) {
return;
}
// 删除应用程序
deleteMyApps(myApps);
}
2.在Activity中执行
delBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
delMyTestAPK();
}
});
public void onActivityResult(int requestCode, int resultCode, Intent data) {
this.finish();
}
执行之后,就可以卸载指定包名的应用。
- android 代码卸载指定APK小结
- android代码打开apk与卸载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 sdk content loader 0% eclipse 打开卡住
- 代码控制EditText是否显示密码样式
- 如何在window上把你的项目提交到github
- c#对应js的编码解码
- 黑马程序员--练习题汇总(未完待续)
- android 代码卸载指定APK小结
- IOS如何使用第三方字体
- 新版SDWebImage的使用(转)
- MikroTik Router OS RB951-2n实现端口镜像端口隔离,防内网回路
- 集成 SVN 插件到 Eclipse 全过程
- git 配置github
- Ubuntu 14.04 64bit上查看网页中的cookies
- SQL SERVER Transactional Replication中添加新表如何不初始化整个快照
- 让ScrollView、ListView充满弹性