The app that I am making uses dropbox, users must give authorisation to enable us to do this. To do this I load a url in a webview which opens up the login for dropbox then shows a "connect" button.
The first problem I had was the webview was opening the default browser. So I could understand why it was doing this I added a WebViewClient and Overrided the onPageStarted method like so..
class AuthCodeWebViewClient extends WebViewClient {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
Log.d(TAG, url);
}
}
Doing this stopped the default browser opening but I cannot press the button within the html. The webview is recognising it as I recieve this in the log...
07-17 16:13:16.700: V/webview(29778): singleCursorHandlerTouchEvent
-getEditableSupport FASLE 07-17 16:13:17.025: I/GATE(29778): DEV_ACTION_COMPLETED
What am I doing wrong so the button doesn't work?
It turns out it was pretty simple and I figured it out about a minute after I posted. I needed to enable javascript
webview.getSettings().setJavaScriptEnabled(true);
Related
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;
}
});
When is shouldOverrideUrlLoading method called?
webView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
}
});
Is it called during initial loading of url? e.g. webView.loadUrl( "file:///android_asset/html/index.html");
Is it called everytime URL of webview changes?
Any reference? I didn't find one. Thanks
It does however, get called when the WebView to load a different URL from the one the user had requested.
Calling loadUrl() will also trigger the shouldOverrideUrlLoading() method. (Only when a new url is about to be loaded.)
Give the host application a chance to take over the control when a new url is about to be loaded in the current WebView. If
WebViewClient is not provided, by default WebView will ask Activity
Manager to choose the proper handler for the url. If WebViewClient is
provided, return true means the host application handles the url,
while return false means the current WebView handles the url.
Ref : public boolean shouldOverrideUrlLoading (WebView view, String url)
Below is the answer for your both the questions:
As per the document, it will manage every time new URL is about to load in current WebView.
I have WebView in my activity and I need to load some local string ( html ) in that webview. Problem is that local html contains images from remoted servers so it needs time to download and show. Is there way to notify user to wait, like spinning dialog or something ? How to notify user to wait content ?
There is not built-in function for doing what you need.
However, you can set a WebViewClient on WebView (see webView.setWebViewClient()) and override the methods onPageStarted() and onPageFinished(). In this way you can show a ProgressDialog or other progress indicator (use a RotateAnimation for example) when the page has started loading and dismiss it later when the page has finished loading.
webView.setWebViewClient(new WebViewClient(){
public void onPageStarted(WebView view, String url, Bitmap favicon){
//show progress indicator
}
public void onPageFinished(WebView view, String url){
//hide progress indicator
}
});
You could do that in your html page using css or javascript.
You could set a webviewCLient to the webview and you will get callback onPageFinished.
ts working fine on all devices Use this link :- Load Web View ProgressDialog
I'm using standard addresses like google and facebook, but loadUrl does nothing, it just sits there at a white screen, but if i pipe html into it using loadData, it works fine. Any ideas or tips? I've got it enabling javascript, and I have this call:
mWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
TextView t;
t = (TextView)findViewById(R.id.pageTitle);
t.setText(view.getTitle());
}
});
Do i need to override anyhting else?
Check whether you have enabled INTERNET permission in Android manifest file.