Android Webview Not Working After Updating Android System webview - android

Making calls to webpage via javascript interface stopped working after updating Android System webview to v- 92.0.4515.105. This issue is mostly on Samsung devices, running Android 11. Works perfectly fine on other devices.
This is my settings:
// attach the interface
webView.addJavascriptInterface(this, "Android");
//setup webview settings
private void setupWebViewClients() {
this.webView.getSettings().setJavaScriptEnabled(true);
this.webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
this.webView.getSettings().setDomStorageEnabled(true);
if (Build.VERSION.SDK_INT >= 19) {
this.webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
this.webView.getSettings().setAppCacheEnabled(true);
}
else {
this.webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
this.webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
//App logic
});
this.webView.setWebViewClient(new WebViewClient() {
public void onPageStarted(WebView view, String url, Bitmap favicon) {
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//App logic
}
public void onPageFinished(WebView view, String url) {
//App logic
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
}
});
}
And I am calling functions this way:
this.webView.loadUrl("javascript:updateGps('dumny',dummy')";
Is there any other settings introduced in Android 11 that I am not aware of? Or it's the bug in Google's Android system webview? Please help me out if there's any work around. Thank you.

Related

Android WebView not loading cached website when internet is off

I am trying to load the cached version of the website when mobile internet is off. But I am only getting a white screen.
Here is my code.
binding.webView.getSettings().setJavaScriptEnabled(true);
binding.webView.getSettings().setDomStorageEnabled(true);
binding.webView.getSettings().setAppCacheEnabled(true);
binding.webView.getSettings().setAllowFileAccess(true);
binding.webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
binding.webView.getSettings().setAppCachePath(getApplicationContext().getCacheDir().getAbsolutePath());
if (!isNetworkAvailable()) {
binding.webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY);
}
binding.webView.setWebChromeClient(new WebChromeClient());
binding.webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
binding.progressBar.setVisibility(View.VISIBLE);
}
#Override
public void onPageFinished(WebView view, String url) {
binding.progressBar.setVisibility(View.GONE);
binding.webView.setVisibility(View.VISIBLE);
}
});
binding.webView.loadUrl("website url here");
Try changing this line:
binding.webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
To:
binding.webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);

WebView: How to load .php file in the 8.0 WebView

i am trying load a .php file in WebView. it was working properly before API level 28 after i updated to API level 28 its not working its showing white screen. nothing is showing i tried all the options.
Here is the code
I am added the safe browsing false in the manifest file also.
I tried searching in the google nothing is helped me if any one done please help in this case to resolve.
String url="https://xxx/xxx/abc.php";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
handleSSLHandshake();
WebView mWebView = (WebView) findViewById(R.id.webView);
// PackageInfo webViewPackageInfo = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// webViewPackageInfo = WebView.getCurrentWebViewPackage();
mWebView.getSettings().setSafeBrowsingEnabled(false);
// Log.d("MY_APP_TAG", "WebView version: " + webViewPackageInfo.versionName);
}
WebViewClientImpl webViewClient = new WebViewClientImpl(this);
mWebView.setWebViewClient(webViewClient);
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
mWebView.getSettings().setBuiltInZoomControls(false);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(url);
if (18 < Build.VERSION.SDK_INT ){
//18 = JellyBean MR2, KITKAT=19
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
}
}
public class WebViewClientImpl extends WebViewClient {
private Activity activity = null;
public WebViewClientImpl(Activity activity) {
this.activity = activity;
}
#Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
webView.loadUrl(url);
// Log.i(TAG,url);
return true;
}
#Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
#Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url) {
}
}
I solved my problem. it was the certificates issues, i just added the following code, its working fine now
#TargetApi(Build.VERSION_CODES.N)
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().toString());
return true;
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}

WebView load on android 5.0 sometimes cause app stuck and crash

I use WebView to load urls and also send and receive Java script calls.
webView.setWebChromeClient(new WebChromeClient() {
#Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100) {
showContentOrLoadingIndicator(true);
}
}
});
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
The code works fine on android < 5 but on lollipop versions sometimes the app simply get totally stuck and sometimes crash.
Any idea why?

WebView shows white screen on Samsung S4 android 4.2.2 for AT&T in onResume()

This is the code to my WebView. It works great on every device I have tested so far, even a Samsung S4. However, a certain Samsung S4, which the client insists it doesn't have a modified software, displays a white screen every time the app is resumed from background. Any ideas?
private void setupWebView() {
// hide the no connection imageview
// show the webview
noConnectionImageView.setVisibility(View.GONE);
webView.setVisibility(View.VISIBLE);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedSslError(WebView view,
SslErrorHandler handler, SslError error) {
handler.proceed();
}
#Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
showNoConnectionImage();
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
// page has started loading
if (mustShowSplashScreen) {
showSplashScreen();
}
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
// page has finished loading
if (mustShowSplashScreen) {
hideSplashScreen();
mustShowSplashScreen = false;
}
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// check for Internet connection
if (ConnectionDetector.isConnected(Main.this)) {
// check if link is external
if (isExternalUrl(url) {
// external link
new OpenLink(Main.this, url);
} else {
// internal link
view.loadUrl(url);
}
} else {
showNoConnectionImage();
Main.this.url = url;
}
return true;
}
});
}

Android WebView not render of web page

I have some web page which open in WebView.
<body onload="window.location.href='htcmd:loaded';">
After load we open back url "htcmd:loaded" and intercept in code.
Like this:
getWebView().getSettings().setJavaScriptEnabled(true);
getWebView().setWebViewClient(new WebViewClient() {
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if ("htcmd:loaded".equals(url)) {
Toast.makeText(getActivity(), "htcmd:loaded", Toast.LENGTH_SHORT).show();
}
return true;
}
});
getWebView().loadUrl("https://some.url");
On android 4.4.2 in first start all is well. But if I kill app and open after first run, web page not render. But if I tap on screen or change orientation web page appears. Where is problem?
SOLUTION: I have two hacks)))
First: add a java script to web page:
<body onload="setTimeout(function(){window.location.href='htcmd:loaded';},3000);">
Second: add code to web client:
#Override
public void onPageFinished(WebView view, String url) {
if (android.os.Build.VERSION.SDK_INT >= 19) {
view.requestFocus();
}
}
try this
w.getSettings().setLoadWithOverviewMode(true);
w.getSettings().setUseWideViewPort(true);
getWebView().getSettings().setJavaScriptEnabled(true);
getWebView().setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return (false);
});
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
getWebView().loadUrl("https://www.google.com");

Categories

Resources