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.](https://static.wixstatic.com/media/b86045_6304427f38644c6ea7132863ed3053c3~mv2.png/v1/fill/w_305,h_500,al_c,q_85,enc_auto/b86045_6304427f38644c6ea7132863ed3053c3~mv2.png)
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?