I want to find out when a user clicks an internal link in a url currently opened in webview. How can I do that?
Thanks,
Farha
Try setting WebViewClient for the WebView and the onPageStarted() method will be called when the page loading is started.
Edit:
To be more clear, this may be a sample code:
WebView wview = (WebView) findViewById(R.id.webView1);
WebViewClient wvClient = new WebViewClient();
wview.setWebViewClient(wvClient);
wvClient.onPageStarted(wview, wview.getUrl(), null);
Related
I realized that not working for under android 4.3 versions.
I have an android app which has webview. When i try to load url "http://instagram.com" it's not working It shows blank page but facebook webpage is working.
It's really important for me please help.
WebView view = (WebView) findViewById(R.id.webView1);
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl("http://www.instagram.com");
Have you tried using the method:
setDomStorageEnabled();
Sets whether the DOM storage API is enabled. The default value is
false.
for example:
WebView view = (WebView) findViewById(R.id.webView1);
view.getSettings().setJavaScriptEnabled(true);
view.getSettings().setDomStorageEnabled(true);
view.loadUrl("http://www.instagram.com");
I had previously problems loading Facebook and Twitter pages in some devices, solved using setDomStorageEnabled() method.
i wonder how to get address of a page inside of a web view on user click, and take that address and open it inside phone browser. for example let's say i open google inside a web view and when i click on one of the links from search then i want to fetch that link and get open it inside phone browser. the code for the web view is as follows:
myWebView = (WebView) findViewById(R.id.webView1);
myWebView.setWebViewClient(new WebViewClient());
myWebView .getSettings().setJavaScriptEnabled(true);
myWebView .getSettings().setDomStorageEnabled(true);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setSupportZoom(false);
myWebView.getSettings().setDomStorageEnabled(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.loadUrl("http://www.google.com/");
you can inject javascript that will find the link and call function from your java activity with android java bridge like How to call javascript from Android?
I am developing an android application in which I want to show a website, which have links in it. When any link is clicked, then it plays an online stream.
Till now I have developed an app which work alright. In this I have used webview to display first screen. The live stream is not supported in webview, so I used webchromeclient.
Now the problem is when any link is clicked, a new browser opens and plays the stream and also shows the address bar and address of page loaded page.
I want to hide the address of new loaded page.
and if possible, also I wnt to keep webchromeclient in existing screen, not a new browser.
in this case you have to customize the WebViewClient like this
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// This is my web site, so do not override; let my WebView load the page
return true;
}
}
}
Then create an instance of this new WebViewClient for the WebView:
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new MyWebViewClient());
for further have a look on this, and read carefully
How to force WebView to open all the urls inside the application?
You need to override the WebViewClient for your WebView.
See here for the details: it's pretty straight forward.
Notice Step 6 in particular.
To open links clicked by the user, simply provide a WebViewClient for
your WebView, using setWebViewClient(). For example:
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
That's it. Now all links the user clicks load in your WebView.
I am trying to use a WebView in my Android application. I am creating my webview in code-side (not in XML). My problem is; when I call loadUrl method of webview, the webview goes fullscreen mode. How can I keep the size of the webview for example 200x200 pixels?
If there is any other option instead of webview, of course welcome :)
Thanks,
Quite possibly what you are seeing is not your activity, but the Browser application, because the URL you linked to did a redirect. Use WebViewClient and shouldOverrideUrlLoading() to catch the redirect and send it back to your own WebView.
#Mahtias Lin, please see my code to create and use WebView;
WebView webView = new WebView(this);
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, 416);
WebSettings webSettings = webView.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webView.setLayoutParams(p);
webView.loadUrl("http://www.google.com/");
Above code is not set my webview to 416px height.
#CommonsWare, I tried your suggested with following code and amazingly it works, thanks.
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return false;
}
});
But this usage brought some new problems. When I override shouldOverrideURLLoading, the webview displays with no-addressbar, no-navigation (back, forward etc...)?
And also, the webview doenst accept user inputs?
Ok, I am editing my question :)
I searched and I found the following additional set to make webview to able to get inputs;
webView.requestFocus(View.FOCUS_DOWN);
On the other hand, I guess I will create my own back, forward buttons and address-bar for my webview. I will also attach "what happened" to this thread when I create my buttons and address-bar.
Best,
WebView wb=new WebView();
wb.setInitialScale(60);
this is used for set layout of the emulator. 60 means % value. we can use 0% to 100%.
See my reply and comments on
how to show a webview inside an activity in the middle of screen
Apply LayoutParams to your WebView or to the Layout (i.e. LinearLayout) that's surrounding the WebView, if any, i.e. setLayoutParams(LinearLayout.LayoutParams(200, 200));