Android - Creating Intents: Web Browser
- Dan Thompson
- Feb 3, 2018
- 1 min read
Hello all,
I really enjoyed the Udacity Android Basics by Google lesson Practice with Intents so I am taking some time to fully explore each of the intents in the Android Common Intents documentation. The one I have most recently looked at is Web Browser.
First I just created a simple button to activate the intent which looks like this:

And the code in activity_main.xml looks like this:
<Button
android:id="@+id/webBrowser"
android:layout_width="@dimen/button_width"
android:layout_height="@dimen/button_height"
android:layout_gravity="center"
android:layout_margin="@dimen/margin"
android:onClick="webBrowser"
android:text="Web Browser"/>
Then I created an activity in MainActivity.java to call the intent when the button is clicked. The following code launches your phones web-browser and takes you to the Udacity homepage.
public void webBrowser(View view) {
Uri webpage = Uri.parse("https://eu.udacity.com/");
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
I welcome any comments or questions about this, especially corrections of anything I can improve. For example, can you get the intent to successfully attach an image?
Recent Posts
See AllI find that adding little notes to myself in my code is very helpful sometimes. It means that I can write pseudocode directly into...
Comments