Creating shortcuts through Intent in Android

We can create shortcut for an application through intent. Its not so difficult. First create an intent with the package name of the application and add some flags to it. Then create another intent and add the first intent to it as extras and broadcast the intent. That is it.

The complete code is,

public class CreateShortcut extends Activity {

public void onCreate(Bundle savedInstanceState) {
Intent shortcutIntent = new Intent();
Log.i("CreateShortcut", "Creating first intent called shortcutIntent");
shortcutIntent.setClassName(getPackageName(), "CreateShortcut");
Intent intent = new Intent();
Log.i("CreateShortcut", "Creating intent for broadcasting");
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "ShortcutName");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, false);

Steps for launching the shortcut is,

-> Long press on the empty part of the home screen

-> Select "Shortcuts" from the dialog that pop-up

-> Select "Applications" from the dialog that pop-up

-> Select "CreateShortcut" from the dialog that pop-up

-> Now, we can see the shortcut for our application in home screen.


Popular posts from this blog

AlarmManager and Notification in Android

Swipe Action and ViewFlipper in Android

Difference between SurfaceView and View in Android