Loading https getting white screen in android webview in version 2.2 - android

I need to load a https url in android webview but it gets loaded with white screen.
I have also handled public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) but still getting white screen on getting loaded with the url but there are no exceptions in the logcat.
below is my code
public class MainActivity extends Activity {
private static final String URL = "https://someurl";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView)findViewById(R.id.webview);
WebSettings settings = myWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
myWebView.loadUrl(URL);
myWebView.setWebViewClient(new MyWebViewClient());
}
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals(URL)) {
return false;
}
Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
handler.proceed();
}
}
}
Looking forward to your reply.
thanks

There are certain SSL certificates that were not supported in Android 2.2, you can try and check to load it in native browser, if it works on browser then it might be supported. If it is not supported, you have atleast following two options
To change the SSL certificate provider assuming you have admin rights to the website
To implement a work around like SSL not working on Android 2.2 (only in 2.3)
Please check whether the SSL is supported on the other Android versions as well.

handler.proceed(); should make the WebView load the https url, have you tried and load a regular http url,and see if the WebView still is white.
There is a bug in Android rendering the WebView white at times.
Try to disable hardware acceleration on the WebView, set android:layerType="software" attribute on the webview in the .xml layout resource.
<WebView
android:id="#+id/webviev"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:layerType="software" />

mWebview.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
//Error happens here and returns an empty page.
}
On 2.3 devices there is a problem with the certification validation.
It might be valid, but when in incorrect order, it fails.
you can call handler.proceed();
But I don't recommend it ! As it breaks required validation.

Related

Android. WebView displaying white page

Why the web view can show a white page, although the page opens in the browser. At first there was an error:
net::ERR_CACHE_MISS
but after I added this code:
wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
there are no errors, but the page does not load, just a white page is displayed. The page opens by clicking on the button inside in webview.Clicking is not processed on the mobile application side.
My manifest also has permission:
<uses-permission android:name="android.permission.INTERNET" />
Please help me. I don’t understand why this can happen. The page also opens successfully on iOS.
Here is my code:
private void initView(String url) {
wvDetail.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("webview://closeScreen")) {
activity.finish();
return true;
} else
return super.shouldOverrideUrlLoading(view, url);
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
Toast.makeText(activity, description, Toast.LENGTH_LONG).show();
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
});
wvDetail.getSettings().setJavaScriptEnabled(true);
wvDetail.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
wvDetail.loadUrl(url);
}
It seems to be a problem with the settings of your webview. Try and add the following settings:
WebSettings settings = wvDetail.getSettings();
//if your page needs javascript
settings.setJavaScriptEnabled(true);
//to handle your cache
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
settings.setAppCacheEnabled(true);
settings.setAppCachePath(cacheDir.path);
To enable some functionalities of JS you should also use setdomStorageEnabled (see this question):
settings.setDomStorageEnabled(true)
If your page is still not loading and you fully trust the web page that you will load, I would also use this settings to give even more access to the webview:
settings.setBlockNetworkImage(false);
settings.setLoadsImagesAutomatically(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
settings.setSafeBrowsingEnabled(false);
}
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setAllowFileAccess(true);
To load the webview with the settings of the meta tag, use:
setUseWideViewPort(true);
Finally you could check upon your webView size and make it fit on your system window like this:
wvDetail.setFitsSystemWindows(true);
Just like a bonus if you are targetting above API level 11, you could set your layer type like this:
wvDetail.setLayerType(View.LAYER_TYPE_HARDWARE, null);
I hope this explanation of the common settings used in a webview makes sense! Depending on your webpage I think that some of them can be useful to you! let me know if it works! :)

Why did my WebView didn't load the owl-carousel content?

I have a webview that will visit a website, the problem here is that
[it didn't load the entire website content
][1]
Then I tried to use Chrome to access the website, and [it loads all the websites content][2](even though a bit messed up since it viewed in mobile).
When I tried to see the content of the missing things (things that didn't showed up in my WebView), I learned it didn't load the content that use owl-carousel,
Is there a way to let my WebView load the owl-carousel content?
P.s I have activated the javascript too
Here's the codes I create that I think lead to the problem
My Webview settings
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setAllowFileAccessFromFileURLs(true);
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setSupportMultipleWindows(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setBuiltInZoomControls(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
And here's my Webview procedure
public class myWebclient extends WebViewClient {
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return super.shouldOverrideUrlLoading(view, url);
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
}
Progress Update
I have tried using AdvancedWebview like what Sudheesh R said, but it's still like previous condition nothing changed, it still don't load the owl-carousel content
Update #2
I̶ ̶t̶r̶i̶e̶d̶ ̶u̶s̶i̶n̶g̶ ̶m̶y̶ ̶f̶r̶i̶e̶n̶d̶ ̶W̶e̶b̶V̶i̶e̶w̶ ̶a̶p̶p̶,̶ ̶a̶n̶d̶ ̶i̶t̶ ̶l̶o̶o̶k̶s̶ ̶l̶i̶k̶e̶ ̶i̶t̶ ̶w̶o̶r̶k̶e̶d̶ ̶o̶n̶ ̶h̶i̶s̶ ̶a̶p̶p̶ ̶b̶u̶t̶ ̶I̶ ̶d̶o̶n̶'̶t̶ ̶k̶n̶o̶w̶ ̶w̶h̶y̶,̶ ̶I̶ ̶w̶i̶l̶l̶ ̶u̶p̶d̶a̶t̶e̶ ̶i̶f̶ ̶I̶ ̶f̶o̶u̶n̶d̶ ̶o̶u̶t̶ ̶h̶o̶w̶.
Alright, I have compared his code with mine, nothing seems comes to light...
Update 3
The only resource I found is this question, but as you see in my code above, I have set the Dom Storage to become enabled... Any help really appreciated
Update 4
Alright, I found out that there's a Jquery method in the website that I haven't initialize yet from my Logcat
So I initialize it but keeping it empty
#JavascriptInterface
public void getxId(){
}
[1]: https://i.stack.imgur.com/3lPNX.png
[2]: https://i.stack.imgur.com/FS6tV.png

Android webview I can't show

https://mobilogr.uludag.edu.tr/Login.aspx
I can't open this website in Android webview
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setUseWideViewPort(true);
settings.setSupportMultipleWindows(true);
settings.setAllowFileAccess(true);
mProgressDialog = ProgressDialog.show(this, "Uygulama Yükleniyor",
"...yükleniyor...");
mWebView.setWebViewClient(new WebViewClient() {
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
if (mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
}
});
mWebView.loadUrl("https://mobilogr.uludag.edu.tr/Login.aspx");
Please check whether your android Android Manifest for the Internet Permission as shown below
<uses-permission android:name="android.permission.INTERNET" />
Does your application have the permission to go on the internet?
<uses-permission android:name="android.permission.INTERNET" />
also, you want to go to this website,
but your url in your script goes to another?
I have faced the similar issue.
The easiest way is to debug and see, the page may have a broken javascript.
You need to remote debug which give you clear error in console.
Try this : https://developer.chrome.com/devtools/docs/remote-debugging
something is wrong with the certificate.
if your ssl Certificate expired or not trusted,webview will refuse to load the webpage.
To avoid this ,you should override onReceivedSslError method like this:
mWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
// super.onReceivedSslError(view, handler, error);
// ignore ssl error
handler.proceed();
}
});
i try this,everything is OK.

reCAPTCHA Not Rendering in Android Webview

I have an Android app that is redirected users to a webpage that contains a reCAPTCHA question. Previously, I was implementing this simply by opening a browser window, and directing the user there. Recently, I changed it to use a webview instead for a better user experience, but the problem is that now for some reason the reCAPTCHA question is not rendered on the page; everything else functions normally. Why would this be, and how might I fix it? I assume this must have something to do with accessing a different domain from the webview (www.google.com), but not sure how to configure things differently that it's not an issue. Here is how I am setting up the Webview. Note that the overridden method is for handling some OAuth authorization process that can happen in this Webview. Even if I comment that out, I have the same problem.
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl(this.url);
myWebView.setWebViewClient(new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading(WebView webView, String url){
Uri uri = Uri.parse(url);
if (url != null && uri.getScheme().equals(NNApplication.CALLBACK_SCHEME)) {
SharedPreferences shPref = getSharedPreferences("NN_PREFS", Activity.MODE_PRIVATE);
new OAuthAccessTokenTask(Authorization.this, consumer, provider, shPref).execute(uri);
webView.setVisibility(View.GONE);
finish();
return true;
}else{
return false;
}
}
#Override
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
handler.proceed() ;
}
});
Likewise, you can view the reCAPTCHA question at the URL below. I already checked, and it's behaving the same between our development site and our live site:
https://www-dev.usanpn.org/user/register
Captcha requires javascript:
myWebView.getSettings().setJavaScriptEnabled(true);

Flash is not loading in Web view in Android

I am trying to Load a webview in Android. Where web page have a swf file but it is not loading. I know there are many question and answer on same topic but no one helped me.
I have already targeted it version 11. And I have put android:hardwareAccelerated="true" too in manifest.xml file.
My code is here-
public class MainActivity extends Activity {
private WebView mWebView;
String url="http://mypages.com/Ch_001/ScoPage.html";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webView);
mWebView.setKeepScreenOn(true);
WebSettings settings = mWebView.getSettings();
settings.setPluginState(PluginState.ON);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.setInitialScale(100);
// wbView.getSettings().setUseWideViewPort(true);
mWebView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.setWebViewClient(new MyWebViewClient());
}
private class MyWebViewClient extends WebViewClient {
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler,
SslError error) {
Log.e("Error VAGARO", error.toString());
handler.proceed();
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
}
}
After one week struggle I got a Flash player from Macromedia, which works for me.
You can search in Google for-"Flash Player 11.1.for Android 4.0 - Macromedia - Adobe" or install APK from this link.
Install this apk in your Android device.
And when you will open it, it will ask for choose default browser.
Choose any browser which support Flash (UC-Browser, Chrome etc).
Now run your any application it will load your Flash video.
Add this code:
webview.getSettings().setPluginsEnabled(true);
add mWebView.loadUrl(url);in onCreate

Categories

Resources