命令:
adb shell
pm clean com.android.providers.contacts
代码::
rootCommand("com.android.contacts");
rootCommand("pm clear com.android.providers.contacts");
import java.io.DataOutputStream;
/**
* 授权root用户权限
*
* @param command 要执行的命令
* */
public boolean rootCommand(String command) {
Process process = null;
DataOutputStream dos = null;
try {
process = Runtime.getRuntime().exec("su");
dos = new DataOutputStream(process.getOutputStream());
dos.writeBytes(command + "\n");
Toast.makeText(DemoActivity.this, "执行命令成功", 1).show();
dos.writeBytes("exit\n");
dos.flush();
process.waitFor();
} catch (Exception e) {
Toast.makeText(DemoActivity.this, "执行命令失败", 1).show();
return false;
} finally {
try {
if (dos != null) {
dos.close();
}
process.destroy();
} catch (Exception e) {
}
}
return true;
}