Android webview - Enable Private Browsing

android, android-webview, java

Solution

    WebView webView = new WebView(this, null, R.id.webView1, true); 
    webView.getSettings().setJavaScriptEnabled(true); 
    webView.loadUrl("google.com");
    Log.v("PrivateBrowsing", "" + webView.isPrivateBrowsingEnabled()); << returns true for me

R.id.webview should be in your layout xml. Hope this works...

Problem

I am trying to create a webview in adroid with private browsing enabled. public WebView (Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) Since: API Level 11 Constructs a new WebView with layout parameters and a default style. context - a Context object used to access application assets. attrs - an AttributeSet passed to our parent. defStyle - the default style resource ID. privateBrowsing - whether this WebView will be initialized in private mode. Can anyone please explain me how to implement it with a breif example.

Original source