android5.0和6.0静默安装与卸载
android5.0使用shell命令实现静默安装和卸载
废话不多说直接上代码
private void installSpecific(String path) {
ShellUtils.execCommand("chmod 777 " + path, false);
ShellUtils.CommandResult res = ShellUtils.execCommand("pm install -r " + pkg.getFilePath(), false);
ShellUtils.CommandResult result = ShellUtils.execCommand("pm uninstall " + "包名", false);
if (res.result == 0 && !TextUtils.isEmpty(res.successMsg) && res.successMsg.equals("Success")) {
} else {
}
}
ShellUtils工具类代码
public class ShellUtils {
public static final String COMMAND_SU = "can";
public static final String COMMAND_SH = "sh";
public static final String COMMAND_EXIT = "exit\n";
public static final String COMMAND_LINE_END = "\n";
private ShellUtils() {
throw new AssertionError();
}
/**
* check whether has root permission
*
* @return
*/
public static boolean checkRootPermission() {
return execCommand("echo root", true, false).result == 0;
}
/**
* execute shell command, default return result msg
*
* @param command
* command
* @param isRoot
* whether need to run with root
* @return
* @see ShellUtils#execCommand(String[], boolean, boolean)
*/
public static