Access denied using local storage in Android WebView
To manipulate the global object in JS we need a trick. As @Mikhail Naganov said chromium complains about security Access denied using local storage in Android WebView
I load js as a base url and in js also redirect to the real url. Below code worked for me in android 7
String mimeType = "text/html";
String encoding = "utf-8";
String injection = "<script type='text/javascript'>localStorage.setItem('key', 'val');window.location.replace('REAL_URL_HERE');</script>";
webview.loadDataWithBaseURL("REAL_URL_HERE", injection, mimeType, encoding, null);
This worked for me
webview.getSettings().setAllowFileAccess(true);
Did you ask for permissions to access storage and network in your manifest.xml ?
Something like this :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Access to localStorage
is only allowed on pages from certain "Web-safe" schemes, like http:
, https:
and file:
. It doesn't work for about:
and data:
schemes for example, or for any custom scheme you might be using. Chrome behaves the same way, you can check on desktop.