I have an issue in getting parameters from a URL mentioned below,
String url = http://example.com/api_callback#access_token=XXXXXXXXXXXXXXX&state=enabled&scope=profile%20booking&token_type=bearer&expires_in=15551999
My code to extract the parameters is as follows:
Uri uri = Uri.parseurl(url); 
Set<String> paramNames = uri.getQueryParameterNames();
However, as you can see a "#" in the URL instead of "?" so that's why I am not able to get the parameters Set.
First thing that came to my mind is to replace "#" with "?" using String.replace method then I thought their might be better solution for this. So if you guys have better solution please help me.
Easiest method:
 String string = url.replace("#","?");
 String access_token = Uri.parse(string).getQueryParameter("access_token");
 Log.d("TAG", "AccessToken: " + access_token);
Now you can get any parameter from the url just by passing their name.
Good Luck
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With