Specific website is not loading in android web view - android

I am trying to load http://www.bing.com or https://www.bing.com in web view but it is not loading. When I debug I found that the onPageFinished() callback is executed and the web view is still blank.
I have tried with other websites such as http://www.google.com it works fine.
Here is my code
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
WebView webView = findViewById(R.id.web_view);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewController());
webView.loadUrl("http://www.bing.com");
}
public class WebViewController extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
In the logs I'm getting the following message when I'm trying to load bing website
2020-04-10 17:41:31.981 6044-6044/com.mawinbet.android I/chromium: [INFO:CONSOLE(0)] "The resource http://www.bing.com/rb/2U/cj,nj/6BsKE-ZQeKe0vHb0vclH0k01aag.js?bu=BUBKDlVY was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: (0)
Can you please tell me how to solve this problem.

Related

HTTP-EQUIV="REFRESH" isn't working on android web view

I have a web page with a basic form (like a newsletter subscription).
The user sends its information and gets a success page with a link to the form submission page. If he doesn't click on the link the page will be automatically redirected after 5 seconds.
<meta http-equiv="refresh" content="5;url=www.site.com" />
So far so good! It works as expected in both desktop and mobile browsers.
Then I created an android app (min API SDK 21) with a web view to load the site.
The problem is that the auto refresh isn't working inside the web view...
Am I missing something? I'm trying to avoid the javascript hack...
Thanks for your time!
EDIT
I notice that when I click on the new form submission page link it opens the default browser instead of rendering it on the web view!
After searching for the problem, I came to a solution by resetting the URL on URL loading.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mWebView = findViewById(R.id.webview);
mWebView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
mWebView.loadUrl(url);
return true;
}
});
mWebView.loadUrl(url);
}
It's working, but I think it can be improved.
My initial problem was that I wasn't setting a WebViewClient.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mWebView = findViewById(R.id.webview);
mWebView.loadUrl(url);
}
Thus, I think I just need to add a WebViewClient and it'll work
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mWebView = findViewById(R.id.webview);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl(url);
}
Note, and if we want javascript to work we need to enable it
mWebView.getSettings().setJavaScriptEnabled(true);

Android WebView not loading website

I am trying to load a website in my android app using webview, but the webview does is not rendering the website.
The website is https://www.rbsdigital.com/
The webview that I'm using is from this github project .
The logs that I get is:
10-12 19:57:14.188 1041-1041/com.teknorial.webviewapp I/chromium: [INFO:CONSOLE(0)] "'window.webkitStorageInfo' is deprecated. Please use 'navigator.webkitTemporaryStorage' or 'navigator.webkitPersistentStorage' instead.", source: (0)
10-12 19:57:14.189 1041-1041/com.teknorial.webviewapp I/chromium: [INFO:CONSOLE(0)] "'webkitIndexedDB' is deprecated. Please use 'indexedDB' instead.", source: (0)
Here's my code. From the github project.
private WebView view;
private static final String RBS_URL = "https://www.rbsdigital.com/";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
view = (WebView) this.findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true);
view.setWebViewClient(new MyBrowser());
view.getSettings().setLoadWithOverviewMode(true);
view.getSettings().setUseWideViewPort(true);
view.setWebChromeClient(new WebChromeClient());
view.loadUrl(RBS_URL);
}
private class MyBrowser extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
Now if I use the default webview like the one from this.
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("https://www.rbsdigital.com/");
The app loads the browser instead of rendering the website from the webview.
If Android webview does not support the website, is it possible to load this by any means?
try this line of code for getting rid of deprecated!
navigator.webkitTemporaryStorage.queryUsageAndQuota (
function(usedBytes, grantedBytes) {
console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
},
function(e) { console.log('Error', e); });
read this answer
I hope it will work fine!

Android webview keep user logged in

I am developing an android application. It is a simple application containing a webview which will load my mvc website.
First page of my application is login page.Once user logs in to the system application page is shown.
Requirement - Is it possible for webview to remember the credentials and allow the auto log in to system when he/she visits next time?
need help. Following is main activity code.
public class MainActivity extends Activity {
WebView webView;
String loginUrl = "mail.xyzabcd.com";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Adds Progress bar Support
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView1);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setLightTouchEnabled(true);
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
webView.loadUrl(loginUrl);
// on clicking a link load it in the same link
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
#Override
public void onPageFinished(WebView view, String url) {
}
});
}
Web View is just a widget which is used to display. It cannot by itself remember data across sessions (if the activity is killed).
What you could do though is to create a resource file that would store the user id and password (based in the logic you want) and then have the Web View check to see if this resource file is present. If present, you could extract details from there. You could do your own encryption as well to secure the data.

WebView loadUrl( always starts browser

trying to load a simple web page in WebView as below
alway leads to the fact that the browser is being launched with it.
The following code I wrote in my main activity besinde defining
"uses-permission android:name="android.permission.INTERNET" "
in the manifest. There is no Exception thrown which I verified with the catch block.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
WebView myWebView = (WebView) findViewById(R.id.myWebView);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://www.google.com");
} catch (Exception e) {
Log.e("MyApp", e.getMessage());
}
}
I cannot imagine what coult be simpler than my scenario. I guess as I do not do things like clicking a link
it is not necessary to do things like
// By default, redirects cause jump from WebView to default
// system browser. Overriding url loading allows the WebView
// to load the redirect into this screen.
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
Do you have any Idea what could go wrong here?
In my very first example I do not use setWebViewClient(... at all but also in that case the browser opens instead of loading the side into the web view.
Thanks and Regards
Dieter
By returning fase in shouldOverrideUrlLoading(), you're instructing the WebView to ignore loading the URL and open the device's default browser instead.
You'll want to replace the contents of that function with:
// By default, redirects cause jump from WebView to default
// system browser. Overriding url loading allows the WebView
// to load the redirect into this screen.
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});

WebView clicks opens mobile browser

There is a WebView which loads mobile-optimized URL (webpage). But when I click on a link, it does not load inside of the WebView (inside of the app), but mobile browser opens.
How to prevent this?
I tried overloading URLs via shouldOverrideUrlLoading(), but it did not help.
This is a code.
webView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setPluginsEnabled(true);
if (Build.VERSION.SDK_INT > 7) {
webSettings.setPluginState(WebSettings.PluginState.ON);
}
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.equals(url)) {
view.loadUrl(url);
return true;
}
return false;
}
#Override
public void onLoadResource(WebView view, String url) {
}
});
webView.loadUrl("http://some-url.com");
EDIT
Does GET or POST posting methods have anything with links' clicks open mobile web browser???
Return true instead of false in shouldOverrideUrlLoading.
From the documentation:
shouldOverrideUrlLoading returns True if the host application wants to
leave the current WebView and handle the url itself, otherwise return
false.

Categories

Resources