Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Is there a programming way to create a web shortcut on home screen

Tags:

android

Do you know is there a programmatic way to create a web shortcut on the phone user's home screen?

What I want to do is:

When the phone user clicks a button in our Android application, the application will then place a website shortcut onto the phone user's home screen.

like image 579
teleme.io Avatar asked Apr 15 '11 11:04

teleme.io


People also ask

Can I create a shortcut to a website on my Android phone?

Android. Launch Chrome for Android and open the website or web page you want to pin to your home screen. Tap the menu button and tap Add to homescreen. You'll be able to enter a name for the shortcut and then Chrome will add it to your home screen.

How do I create a custom shortcut on Android?

Find the app you want to create a shortcut for and long-press on its icon. Tap Add to home. On some Android devices, you will need to long-press the icon and drag the app to the home screen. The app's icon should then appear in the top-right corner of your Home screen on your Android tablet or smartphone.

How do I create a shortcut to a website on Chrome for Android?

To add shortcut links to the sites on the Home screen with Chrome Android, firstly launch the site whose link you wish to add to the Home screen. Now, tap on the three dots>Add to home screen>Add. This will automatically add the shortcut link to the home screen of your Android phone.


1 Answers

First you'll need to add a permission to your manifest.xml

<uses-permission
            android:name="com.android.launcher.permission.INSTALL_SHORTCUT">
</uses-permission>

You'll need to build an intent to view the webpage. Something like...

Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.blablaba.com"));

You can test this by creating a little test app and doing startActivity(i); This should open the browser. Once you verified that the above intent is correct you should move on to the next step.

Now you'll need to actually install the shortcut.

    Intent installer = new Intent();
    installer.putExtra("android.intent.extra.shortcut.INTENT", i);
    installer.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN");
    installer.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", I THINK this is a bitmap); //can also be ignored too
    installer.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    sendBroadcast(installer)

;

It's also possible some home screens don't accept this, but most do. So enjoy.

EDIT: Icon can be set to the shortcut using:

installer.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", Intent.ShortcutIconResource.fromContext(mContext, R.drawable.icon));
like image 173
Mike dg Avatar answered Jan 01 '23 21:01

Mike dg