[android]代码库
//读取报名,判断某app是否装在移动设备上
public static void uninstallSoftware(Context context, String packageName) {
PackageManager packageManager = context.getPackageManager();
try {
PackageInfo pInfo = packageManager.getPackageInfo(packageName,
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
//判断是否获取到了对应的包名信息
if(pInfo!=null){
return true;
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return false;
}
//判断某app是否装在移动设备上,如果已经存在,则卸载
public static void uninstallSoftware(Context context, String packageName) {
PackageManager packageManager = context.getPackageManager();
try {
PackageInfo pInfo = packageManager.getPackageInfo(packageName,
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
//在这里也是判断当前应用是否安装
if(pInfo!=null){
//删除软件
Uri uri = Uri.parse("package:"+ name);
Intent intent = new Intent(Intent.ACTION_DELETE, uri);
context.startActivity(intent);
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}