FelasDroid
FelasDroid

Reputation: 643

Get Parameter from a URL Android

I have a WebView to navigate in internet in my app. How i can get parameter from a url when i try to login in a page ?..

For example i have form in HTML, with username and password parameter, the complete url is: mysite/?username=48djdui&password=fdsajfo

but, how i can get this parameter? and take this url?

Sorry for my english..

The code for now is:

webView.setWebViewClient(new WebViewClient());



        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setSupportZoom(true);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setBuiltInZoomControls(true);

 webView.loadUrl(inputurl);

Upvotes: 4

Views: 13214

Answers (3)

Varundroid
Varundroid

Reputation: 9234

val url = "https://graph.facebook.com/me/home?limit=25&since=1374196005"
val sanitizer = UrlQuerySanitizer(url)
sanitizer.getValue("limit")

Make use of class called UrlQuerySanitizer. It can also give you list of parameters.

Upvotes: 2

Massimo Milazzo
Massimo Milazzo

Reputation: 3532

Try this

String url = "http://www.yourdomain.com/?param1=ONE&param2=TWO";
List<NameValuePair> parameters = URLEncodedUtils.parse(new URI(url));
for (NameValuePair param: parameters) {
    String name = param.getName();
    String value = param.getValue();
}

Or this

Uri url = Uri.parse(webView.getUrl());
Set<String> paramNames = url.getQueryParameterNames();
for (String key: paramNames) {
    String value = url.getQueryParameter(key);
}

Upvotes: 9

dionbosschieter
dionbosschieter

Reputation: 57

You could use the getUrl function of WebView.

String url = webView.getUrl();

This function returns a String, you can use this String to exract the parameters.

See here: http://developer.android.com/reference/android/webkit/WebView.html#getUrl%28%29

Upvotes: 0

Related Questions