The API specification reads as follows for the WebView constructor that allows private browsing to be enabled:
(from http://developer.android.com/reference/android/webkit/WebView.html)
WebView(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing)
This constructor was deprecated in API level 17. Private browsing is no longer supported directly via WebView and will be removed in a future release. Prefer using WebSettings, WebViewDatabase, CookieManager and WebStorage for fine-grained control of privacy data.
As of API 19 (KitKat) private browsing is disabled. Attempting to invoke this constructor with a value of true results in an IllegalArgumentException.
The alternatives suggested will not be even marginally effective in replicating the behavior of private browsing. The CookieManager class is a singleton, with all settings being applied to the entire application. There is no "fine grained control of privacy data" with this approach. The only control provided by CookieManager is the ability to disable cookies altogether, for EVERY WebView present in the app. This change means that third-party browsers are no longer able to replicate the private browsing feature of Google's own browser in any capacity.
I'd greatly appreciate any suggestions for working around this behavior. As of yet I can find nothing in the API that would make any resemblance of the former private browsing capability possible.
Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.
Google combined WebView with Google Chrome for versions 7.0, 8.0 and 9.0. However, with Android 10.0, it went back to having it as a separate component. Users can update WebView in Android 10 through Google Play Store.
The Android system webview custom cache file has been deprecated and removed in Android 13. New apps and any app updates will now use the operating system default cache location.
In addition to what I have in the comment, this is another place where having multiple processes is justified. Since CookieManager
is a singleton, separate processes will have separate CookieManager
instances. "Private browsing" WebView
instances could be in a separate process from the "regular browsing" WebView
instances.
This does have downsides:
They cannot be in the same activity, as a View
from one process cannot be rendered in another process. So, if the UI metaphor for the browser implies several WebView
widgets in a single activity (e.g., tabs), that UI metaphor will need to be tweaked to allow for "context switching" between regular and private browsing.
This will consume more system RAM, which is bad for the user, albeit good for the developer (less likelihood of OutOfMemoryError
exceptions).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With