I am using WebView to create a user Account in Android.In creating a user,User need to traverse 3 pages in order to complete full registration.I need to inject the script on 2nd page but the problem is the url for creating user in all 3 pages is same (for ex www.mywebpage/createUser).So the problem is - As the url is same I am not able to know that user is on a particular url,then I can inject the script.Is there any other way like (catching string or any id or any tag) so that I can differentiate between pages.
Asked
Active
Viewed 1,279 times
-1
-
@Shabbir Dhangot I dont want url as my question is clearly saying url is same in creating user.I want to distinguish based on the contents not on the url – FiXiT May 09 '16 at 12:48
-
I know how to get Url but I want to distinguish on the basis of Contents of the page – FiXiT May 09 '16 at 12:50
-
If you have access to the webpage, your best solution would be to implement a Javascript interface in your Android code, and from the Registration page trigger the interface so you can inject what you need to. If you do not have access to the web app and the URL is the same as you seem to state, you may need to pull the HTML data from the page and parse based on changes (http://stackoverflow.com/questions/8200945/how-to-get-html-content-from-a-webview) BUT if it is a SPA you may run into other issues. – aminner May 09 '16 at 13:11
2 Answers
1
You can use WebViewClient to achieve this
WebView webview = new WebView(context);
webview.setWebViewClient(new WebViewClient()
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
System.out.println("your current url when webpage loading.." + url);
}
@Override
public void onPageFinished(WebView view, String url) {
System.out.println("your current url when webpage loading.. finish" + url);
super.onPageFinished(view, url);
}
@Override
public void onLoadResource(WebView view, String url) {
// TODO Auto-generated method stub
super.onLoadResource(view, url);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
System.out.println("when you click on any interlink on webview that time you got url :-" + url);
return super.shouldOverrideUrlLoading(view, url);
}
});
Krishna
- 706
- 5
- 22
-
@Krisha thanks but I know this will give me the current Url.In my case when user register the url is same for 3 pages. I want to distinguish between those pages which cant be distinguished by url only – FiXiT May 09 '16 at 12:53
0
WebView has public method getUrl() which returns url string. Create object of your web view and find it by id. Or instantiate in a way you need... and just call getUrl() on the object and assign to string.
daxgirl
- 744
- 4
- 10