Skip to content

Instantly share code, notes, and snippets.

@Kishanjvaghela
Created February 26, 2016 11:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kishanjvaghela/7c7dd582f3dadd22bfe7 to your computer and use it in GitHub Desktop.
Save Kishanjvaghela/7c7dd582f3dadd22bfe7 to your computer and use it in GitHub Desktop.
Utility methods
/**
* get android id of device.
*
* @param context app context
* @return android id
*/
public static String getAndroidID(Context context) {
if (context != null) {
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
} else {
return "N/A";
}
}
/**
* get query parameter from url
*
* @param url url
* @return <key,value> pair of query parameter
*/
public static Map<String, String> getQueryMap(String url) {
String[] params = url.split("&");
Map<String, String> map = new HashMap<>();
for (String param : params) {
String name = param.split("=")[0];
String value = param.split("=")[1];
map.put(name, value);
}
return map;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment