Skip to content

Instantly share code, notes, and snippets.

@groverankush
Created March 19, 2018 18:12
Show Gist options
  • Save groverankush/faec047275e3307588245537ee0f057d to your computer and use it in GitHub Desktop.
Save groverankush/faec047275e3307588245537ee0f057d to your computer and use it in GitHub Desktop.
Gist to answer Lesson 3 Quiz
final static String BASE_URL = "https://developer.android.com/guide/components/intents-common.html";
final static String PARAM_SOURCE = "utm_source";
final static String PARAM_MEDIUM = "utm-medium";
final static String PARAM_CAMPAIGN = "utm-campaign";
final static String SEGMENT_PHONE = "Phone";
public static URL buildUrl() {
/*I've made some assumptions. In an ideal scenario, all the query params can be passed in the function iteself.
* But for the sake of brevity, it is avoided.
*/
Uri builtUri = Uri.parse(BASE_URL).buildUpon()
.appendQueryParameter(PARAM_SOURCE, "udacity")
.appendQueryParameter(PARAM_MEDIUM, "course")
.appendQueryParameter(PARAM_CAMPAIGN, "android_basics")
.encodedFragment(SEGMENT_PHONE)
.build();
URL url = null;
try {
url = new URL(builtUri.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
}
return url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment