adb toolbar - 清除android應用程序用戶數據





button add (8)


命令pm clear com.android.browser需要root權限。
所以,先運行su

以下是示例代碼:

private static final String CHARSET_NAME = "UTF-8";
String cmd = "pm clear com.android.browser";

ProcessBuilder pb = new ProcessBuilder().redirectErrorStream(true).command("su");
Process p = pb.start();

// We must handle the result stream in another Thread first
StreamReader stdoutReader = new StreamReader(p.getInputStream(), CHARSET_NAME);
stdoutReader.start();

out = p.getOutputStream();
out.write((cmd + "\n").getBytes(CHARSET_NAME));
out.write(("exit" + "\n").getBytes(CHARSET_NAME));
out.flush();

p.waitFor();
String result = stdoutReader.getResult();

StreamReader

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.CountDownLatch;

class StreamReader extends Thread {
    private InputStream is;
    private StringBuffer mBuffer;
    private String mCharset;
    private CountDownLatch mCountDownLatch;

    StreamReader(InputStream is, String charset) {
        this.is = is;
        mCharset = charset;
        mBuffer = new StringBuffer("");
        mCountDownLatch = new CountDownLatch(1);
    }

    String getResult() {
        try {
            mCountDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return mBuffer.toString();
    }

    @Override
    public void run() {
        InputStreamReader isr = null;
        try {
            isr = new InputStreamReader(is, mCharset);
            int c = -1;
            while ((c = isr.read()) != -1) {
                mBuffer.append((char) c);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (isr != null)
                    isr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            mCountDownLatch.countDown();
        }
    }
}

使用adb shell清除應用程序數據

adb shell pm clear com.android.browser

但是從應用程序執行該命令時

String deleteCmd = "pm clear com.android.browser";      
        Runtime runtime = Runtime.getRuntime();
        try {
            runtime.exec(deleteCmd);
        } catch (IOException e) {
            e.printStackTrace();                
        }

問題:

雖然我已經給出了以下許可,但並不清楚用戶數據既沒有給出任何例外。

<uses-permission android:name="android.permission.CLEAR_APP_USER_DATA"/>

題:

如何使用adb shell清除應用程序數據?




Afaik瀏覽器應用程序數據對於其他應用程序不可清除,因為它存儲在private_mode 。 所以執行這個命令可能只能在rooted設備上運行。 否則,你應該嘗試另一種方法。




adb卸載com.package.packagename

在ADB外殼上執行此命令。

adb卸載com.package.packagename -k

-k將保留用戶數據




這個命令為我工作:

adb shell pm clear packageName



你好UdayaLakmal,

public class MyApplication extends Application {
    private static MyApplication instance;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
    }

    public static MyApplication getInstance(){
        return instance;
    }

    public void clearApplicationData() {
        File cache = getCacheDir();
        File appDir = new File(cache.getParent());
        if(appDir.exists()){
            String[] children = appDir.list();
            for(String s : children){
                if(!s.equals("lib")){
                    deleteDir(new File(appDir, s));
                    Log.i("TAG", "File /data/data/APP_PACKAGE/" + s +" DELETED");
                }
            }
        }
    }

    public static boolean deleteDir(File dir) {
        if (dir != null && dir.isDirectory()) {
            String[] children = dir.list();
            for (int i = 0; i < children.length; i++) {
                boolean success = deleteDir(new File(dir, children[i]));
                if (!success) {
                    return false;
                }
            }
        }

        return dir.delete();
    }
}

請檢查並告訴我...

你可以從here下載代碼




要清除應用程序數據請嘗試這種方式。

    public void clearApplicationData() {
    File cache = getCacheDir();
    File appDir = new File(cache.getParent());
    if (appDir.exists()) {
        String[] children = appDir.list();
        for (String s : children) {
            if (!s.equals("lib")) {
                deleteDir(new File(appDir, s));Log.i("TAG", "**************** File /data/data/APP_PACKAGE/" + s + " DELETED *******************");
            }
        }
    }
}

public static boolean deleteDir(File dir) {
    if (dir != null &amp;&amp; dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            boolean success = deleteDir(new File(dir, children[i]));
            if (!success) {
                return false;
            }
        }
    }

    return dir.delete();
}



如果您想手動執行操作,則還可以通過單擊Settings–>Applications–>Manage Aplications–>您的應用Settings–>Applications–>Manage Aplications–> “Clear Data”按鈕“Clear Data”用戶數據

or Is there any other way to do that?

然後在這裡下載代碼




你只需在發送你的意圖的同時發送額外信息。

喜歡這個:

Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
intent.putExtra("Variable name", "Value you want to pass");
startActivity(intent);

現在在SecondActivityOnCreate方法中,您可以像這樣獲取額外的內容。

如果您發送的值long

long value = getIntent().getLongExtra("Variable name which you sent as an extra", defaultValue(you can give it anything));

如果您發送的值是一個String

String value = getIntent().getStringExtra("Variable name which you sent as an extra");

如果您發送的值是Boolean

Boolean value = getIntent().getBooleanExtra("Variable name which you sent as an extra", defaultValue);






android adb user-data