I'm using Webview in my app , i have a simple website, it has two buttons such as Female and Male , if user click that button i want to show the toast message using android app to users which button they clicked
This is my Webview content
I wanted to know that how to get current activity from the webview and i have another doubt also. how to get the current page url in my android app . for example . if give url like www.stackoverflow.com , the user can browse wherever they want , but at particular time , i need to find out user is in which page.?
Thanks in advance. if this question has any mistakes please let me know
Please have a look at WebViewClient
private String mUrl = "";
...
mWebView.setWebViewClient(new WebViewClient()
{
#Override
public void onPageFinished(WebView view, String url)
{
mUrl = url;
}
});
Related
How to go EXACTLY to http://example.com/index.html#label if content to webview loading via WebView.loadDataWithBaseURL ?
By default webview go to root only. How go to label ?
WebView doesn't have such functionality from the box.
You can achieve this with the help of javascript, but this is a bit of ugly.
You should load your html page and then add javascript code to it.
After this you can load your webview and call javascript methods from current page.
Check this link for example how that can be done.
WebView jump to anchor using loadDataWithBaseUrl
Example goes here
webContents.setWebViewClient(new WebViewClient(){
#Override
public void onPageFinished(WebView view, String url) {
String id = "895884";
webContents.loadUrl("javascript:scrollAnchor(" + id + ");");
}
});
When I type the url in the text box and click on the Go button the webview loads the required page but when I click on any link inside the webview the address bar which is the text box is not updated with the exact url? How do I go about doing this?
I am trying all varies ways on google not getting the solution - probably key words are wrong. :( - Help on this would be great.
Thanks!
You need to Override onPageFinished method
#Override
public void onPageFinished(WebView view, String url) {
urlEditText.setText(url, TextView.BufferType.NORMAL);
super.onPageFinished(view, url);
}
I am new to Android WebView, in my application i need to display a web site conatins 3 web pages. In the first web page there will be a link to navigate to the second page and second to third page. I given the URL in the WebView, the first page is displayed perfectly, when i click the link it directly opens the browser application to display the second page. But i want to display the second page in the WebView itself. Please find my code below:
WebView forumView=(WebView)findViewById(R.id.forumView);
forumView.getSettings().setJavaScriptEnabled(true);
forumView.loadUrl("url");
As i said i am very new to WebView my code might be wrong, please help me to solve this problem.
Thanks in Advance,
Rajapandian
This piece of code will help you.
wbb = (WebView) findViewById(R.id.webView_tobe_loaded);
WebSettings wbset=wbb.getSettings();
wbset.setJavaScriptEnabled(true);
wbb.setWebViewClient(new MyWebViewClient());
String url="http://www.google.com";
System.out.println(getdeviceid());
wbb.getSettings().setJavaScriptEnabled(true);
wbb.loadUrl(url);
You'll have to intercept the clicks yourself if you don't want the default Android behavior.
You can monitor events in a WebView using a WebViewClient. The method you want is shouldOverrideUrlLoading(). This allows you to perform your own action when a particular URL is selected.
You set the WebViewClient of your WebView using the setWebViewClient() method.
If you look at the WebView sample in the SDK there's an example which does just what you want. It's as simple as:
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
hey, an android noob needs help here.
i'm trying to get my webview browser to delete the browser history after the homepage has been loaded (so the next user that comes around this public app doesn't see the previous session)
i've made a webview client and put a
public void onPageFinished(WebView webView, String Url ) {
Browser.clearHistory();
but don't know how to change the String Url to the url of the apps homepage.
I also tried adding a second function to my homebutton onclicklistener, but no luck as well, if someone wants to help i can paste that bit of code as well.
thanks
Here how I did;
#Override
public void onPageFinished(WebView view, String url) {
junc.pg.setVisibility(View.INVISIBLE);
if(url.indexOf("a_string_unique_to_your_homepage")!=-1) {
view.clearHistory();
}
}
Here, you can define a unique string for your url. For example if your homepage url is
www.example.com
you can call it with
www.example.com?12345abc
and search for this unique number 12345abc.
It works, I have tested several times.
Sorry Matt you canĀ“t delete your Browser history programatically in Android.
you will achieve that manually
Browser ..> Settings > Clear History > OK
What about?
Browser.clearHistory(getContentResolver());
Browser.clearSearches(getContentResolver());
I'm making an application that contains button's and those buttons control an embedded browser. My problem is that I want to see the button's and the web page in the same layout, but when i click on a button this will open a web page and don't show the button, can anyone help me?
If I understand correctly your problem is that following a link opens the standard browser not your WebView, right ?
Add this to your WebView to change that behavior
// this is to prevent that when clicking a new URL from the displayed
// page the default web browser launches
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
You need to use a Layout that supports more than one child. Take a look here