top of page

Android - Creating Intents: Web Browser

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:

Android App showing a single WEB BROWSER button.

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?


Featured Posts
Recent Posts
Archive
Search By Tags
Follow Us
  • LinkedIn Social Icon
  • Pinterest Social Icon
  • Facebook Basic Square

© 2023 by Coming Soon

Proudly created with Wix.com

bottom of page