Question

I want to clear application data like i can do it from settings. I need to clear login information in WebView when i am login to facebook or twitter, because when i log on once for each of the following uses the same data automatically

I try this: http://www.hrupin.com/2011/11/how-to-clear-user-data-in-your-android-application-programmatically

didn't work, login information are still in browser

I try reset app:

Intent i = getBaseContext().getPackageManager()
             .getLaunchIntentForPackage( getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

also

@Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        view.clearCache(true);

        if(b){
            Log.d("WEBVIEW", "onFinisghed b true");
        Map<String, String> noCacheHeaders = new HashMap<String, String>(2);
        noCacheHeaders.put("Pragma", "no-cache");
        noCacheHeaders.put("Cache-Control", "no-cache");
        view.loadUrl(url, noCacheHeaders);
        b = false;
        }...

Most of the entries refers to the first method which is described in the link, but it does not work in my case, any ideas?

Was it helpful?

Solution

Try clearing the browser cookies. Logon credentials are often stored in browser cookies, which you can delete by a call to

CookieManager.getInstance().removeAllCookie();

Update:

CookieManager.getInstance().removeAllCookie() was deprecated in Android SDK 21 (Lollipop), and was replaced by CookieManager.getInstance().removeAllCookies(ValueCallback callback). As of November 2018, removeAllCookie() stills works as specified. Also, in the newer method removeAllCookies(ValueCallback callback), the callback function can be null if you don't want to be notified about removed cookies. Thus, it's safe to use

CookieManager.getInstance().removeAllCookies(null)

as a direct replacement for CookieManager.getInstance().removeAllCookie() when targeting devices after Android SDK 21.

CookieManager documentation is here.

OTHER TIPS

CookieManager.getInstance().removeAllCookie();

above method will resolved problem but This method was deprecated in API level 21 so use removeAllCookies(ValueCallback) instead.

This method is asynchronous. If a ValueCallback is provided, onReceiveValue() will be called on the current thread's Looper once the operation is complete. The value provided to the callback indicates whether any cookies were removed. You can pass null as the callback if you don't need to know when the operation completes or whether any cookies were removed, and in this case it is safe to call the method from a thread without a Looper.

ValueCallback: a callback which is executed when the cookies have been removed

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top