Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to create a launcher

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

like image 708
Pierre Avatar asked Jan 05 '11 11:01

Pierre


2 Answers

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

like image 105
xil3 Avatar answered Oct 20 '22 09:10

xil3


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!
    }
}
like image 44
Blundell Avatar answered Oct 20 '22 09:10

Blundell