Created
March 19, 2018 18:12
-
-
Save groverankush/faec047275e3307588245537ee0f057d to your computer and use it in GitHub Desktop.
Gist to answer Lesson 3 Quiz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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