How can I get parameters from URL in Android?

JavaAndroid

Java Problem Overview


I have a URL like this:

http://www.chalklit.in/post.html?chapter=V-Maths-Addition%20&%20Subtraction&post=394

How to get the value of parameter of chapter and post?

My URL contains '&' in the value of chapter parameter.

Java Solutions


Solution 1 - Java

You can use the Uri class in Android to do this; https://developer.android.com/reference/android/net/Uri.html

Uri uri = Uri.parse("http://www.chalklit.in/post.html?chapter=V-Maths-Addition%20&%20Subtraction&post=394");
String server = uri.getAuthority();
String path = uri.getPath();
String protocol = uri.getScheme();
Set<String> args = uri.getQueryParameterNames();

Then you can even get a specific element from the query parameters as such;

String chapter = uri.getQueryParameter("chapter");  //will return "V-Maths-Addition "

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionShubham ChauhanView Question on Stackoverflow
Solution 1 - Javajason.kaisersmithView Answer on Stackoverflow