I've never developed for Android before, so please consider me 100% dumb when you answer :)
I would like to create an application launcher that will open the default web browser to a given url. In other words, I want to make an icon with my website logo, and when you click on it, it opens the site in your default web browser.
Could someone direct me towards a tutorial/documentation page to achieve this? Or if it's really simple, maybe show me some code here?
Thanks for your time!
P
If I understand what you need correctly, you could just create a simple app with just 1 activity and stick this in the onCreate:
Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.yourwebsite.com"));
startActivity(viewIntent);
And here are some resources on creating a simple app:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/HelloWorld.html
And here is some info on how you can set your app icon:
http://www.connorgarvey.com/blog/?p=97
I have written a tutorial for just this :=D
http://www.anddev.org/code-snippets-for-android-f33/button-to-open-web-browser-t48534.html
Modified version:
package com.blundell.twitterlink;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sendToTwitter(); // Open the browser
finish(); // Close this launcher app
}
protected void sendToTwitter() {
String url = "http://twitter.com/blundell_apps"; // You could have this at the top of the class as a constant, or pass it in as a method variable, if you wish to send to multiple websites
Intent i = new Intent(Intent.ACTION_VIEW); // Create a new intent - stating you want to 'view something'
i.setData(Uri.parse(url)); // Add the url data (allowing android to realise you want to open the browser)
startActivity(i); // Go go go!
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With