I have an application with WebView. In my WebView, I will get next page URL from:
public boolean shouldOverrideUrlLoading(WebView view, String URL)
and I'm saving this URL for further process. I'm also using:
webView.loadUrl(baseUrl)
By using shouldOverrideUrlLoading function, I will get the URLs loading by my WebView. But in facebook case (page loaded as mobile view), I didn't get the URLs which I'm switching through facebook.
For instance: First I loaded facebook I got that URL, then I go to my home, then my page, then events, then other people profile, pages etc. I didn't get any of the URLs except the first one.
Related
My Android app uses a WebView to let the user navigate around the Internet, but occasionally it encounters a site that navigates using its own funky schema. For example, if you search for "aliexpress", the app will take you to the site's Home page just fine.
However, if you select any of the buttons on the top, WebView throws an error:
All I needed to do was call shouldOverrideUrlLoading() as follows:
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Uri current_page = request.getUrl();
if (!current_page.toString().startsWith(("http://")) && !current_page.toString().startsWith(("https://"))) return true;
return false;
}
I have android app hosting a web site in WebView. It works fine, but has one issue. Whenever users search in Google and click on page of this site, the application is opening not at that page but on home page of the web site.
For example: they click on www.example.com/blog - WebView app is open but it shows homepage, not blog.
Links (navigation) works fine inside of application when it starts.
try these code
myWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().toString());
return false;
}
});
when you click on any link on webview then view.loadurl() method again load new url.
My android app has a webview which directly goes to the remote PHP site and shows user the registration form.
My question is, once user get registered successfully I want to close the webview and start another activity which is in native view. But how can I know whether he/she got registered successfully or not?
Thanks
You can do it this way:
In your PHP code, when the user gets registered successfully, redirect user to a unique link(this link will be used in your android code). Let's assume the link you redirect user to is "https://blablabla.com/successfully_registered"
In the WebViewClient's OnPageStarted method used by your WebView, Get the URL and check if it's similar to your redirect URL we assumed you used in your PHP code.
For Example:
WebView wv = findViewById(R.id.webview);
wv.setWebViewClient(new WebViewClient(){
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon){
//check if URL is similar to redirect URL
if(url.contains("https://blablabla.com/successfully_registered")){
view.stopLoading();
//user have been successfully registered. Start another activity or do something else...
}
}
});
I have an Activity in my app which has a Webview in it which opens a URL provided to it and is then redirected to the landing page of the website. The issue I'm facing is once the user is on landing page the redirection is same page redirection i.e. if the landing page is
www.example.com/landing
The redirection is
www.example.com/landing/#other_page
Which does not call the
onPageStarted(WebView view, String url, Bitmap favicon)
of the webview, but
onPageFinished(WebView view, String url)
is called.
Is there a way to track when the redirect is starting to load since I need to log the time required to load a page even if the page is same page redirection.
Thanks in advance!
Edit: According to the documentation:
onPageStarted will not be called when the contents of an embedded frame changes, i.e. clicking a link whose target is an iframe, it will also not be called for fragment navigations (navigations to #fragment_id).
Which is exactly my case. Is there any other way to track the start and end of loading of fragment navigation?
I think you are looking for that method
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.d("Webview", url);
return false;
}
});
I have an Android app with that displays a mobile website (WebView), in the mobile website there are links redirecting to a PDF, Excel and video files.
When try to open it in my regular browser my phone asks to open it with another app or it start a download, so I can open it afterwards.
But in my WebView app it either doesn't work, no response or it displays a "Page unavailable" error.
Is it even possible?
To handle links in WebView, you can use the shouldOverrideUrlLoading method of WebViewClient class. Consider the following example;
WebView webView = (WebView) findViewById(R.id.infoView);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Assuming you are giving link to some PDF file.
if (url.contains(".pdf")) {
// Now do what you want to with the url here
}
return true;
}
}
This way, you can intercept any link tapped in WebView and then do whatever you want.