I am trying to read local storage data from javascript using WebView in android.
Here is my code
@Override
public void onPageFinished(WebView view, String url) {
getLocalStorageAndSaveOnAndroidPref("androidDeliveryAppStickyNotificationTitle", view);
}
public static void getLocalStorageAndSaveOnAndroidPref(String key, WebView view) {
String JAVASCRIPT_LOCAL_STORAGE_LOOKUP = "javascript:window";
Log.d(TAG, "getLocalStorageAndSaveOnAndroidPref: function called");
view.evaluateJavascript(JAVASCRIPT_LOCAL_STORAGE_LOOKUP.concat(".localStorage.getItem('" + key + "')"), value -> {
Log.d(TAG, "getLocalStorageAndSaveOnAndroidPref: "+value);
SharePref.setDataPref(key, value);
});
}
But this is giving me null when it's loaded the first time.
I want to achieve that the local storage data should be loaded the first time the page is finished.
Any idea how to achieve that.