您的位置:首页 > 其它

清空联系人数据

2015-12-13 22:11 309 查看
命令:

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;
    }  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: