Anas Yousuf
Anas Yousuf

Reputation: 523

How to delete/clear hidden data of app in android programmatically?

Basically my App displays the WebView of a website. and it logins (Google SignIn) correctly but after logout and pressing on LogIn Again doesn't take my account, instead it saves that Gmail once, and clicking log-in again uses previous login credentials. and it gets solved if I clear my app data using device settings. I am trying to reach and Clear my App Data Programmatically.

So far I have been able to delete app data using ( https://www.hrupin.com/2011/11/how-to-clear-user-data-in-your-android-application-programmatically )

But this link was useful if app data exist normally on DeviceFileExplorer data -> data -> package-name, and my problem is that app data is generated hidden inside internal storage (OS security).

Using these below commands I have been able to display them up on DeviceFileExplorer.

adb shell  
run-as com.your.packagename   
cp /data/data/com.your.packagename/

I have read that this command copies(not move) my hidden package data to this /data/data/com.your.packagename/

So deleting this /data/data/com.your.packagename/ won't help.

Upvotes: 1

Views: 2606

Answers (1)

Akash Pal
Akash Pal

Reputation: 1115

private void clearData() {
    try {
        if (Build.VERSION_CODES.KITKAT <= Build.VERSION.SDK_INT) {
            ((ActivityManager) getSystemService (ACTIVITY_SERVICE)).clearApplicationUserData();
        } else {
            Runtime.getRuntime().exec("pm clear " + getApplicationContext().getPackageName());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Upvotes: 1

Related Questions