1、调用系统的卸载:
Intent intent = new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + pkg_name));
startActivity(intent);
2、调用adb卸载:
runCmd("adb uninstall " + pkg_name);
/**
* 通过adb卸载应用
*
* @param cmd
* @return
*/
public String runCmd(String cmd) {
try {
System.out.println(cmd);
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(cmd);
int result = process.waitFor();
BufferedReader successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s;
StringBuilder successMsg = new StringBuilder();
while ((s = successResult.readLine()) != null) {
successMsg.append(s).append('-');
}
StringBuilder errorMsg = new StringBuilder();
while ((s = errorResult.readLine()) != null) {
errorMsg.append(s);
}
System.out.println(successMsg.toString() + ":" + errorMsg.toString());
return successMsg.toString() + ":" + errorMsg.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
注意:1、这两种种卸载的弊端就是只能卸载第三方安装的应用,要是卸载系统的需要root权限
2、adb卸载的方式可以简化下,不需要那么多代码,自己去看吧
3、最好在卸载的时候使用try{}catch{}判断一下,,,