Search code examples
javaandroidfacebook-graph-api

How to parse or split URL Address in Java?


If I have url address.

https://graph.facebook.com/me/home?limit=25&since=1374196005

Can I get(or split) parameters (avoiding hard coding)?

Like this

https /// graph.facebook.com /// me/home /// {limit=25, sincse=1374196005}


Solution

  • Use Android's Uri class. http://developer.android.com/reference/android/net/Uri.html

    Uri uri = Uri.parse("https://graph.facebook.com/me/home?limit=25&since=1374196005");
    String protocol = uri.getScheme();
    String server = uri.getAuthority();
    String path = uri.getPath();
    Set<String> args = uri.getQueryParameterNames();
    String limit = uri.getQueryParameter("limit");