Skip to content

Instantly share code, notes, and snippets.

@konklone
Created November 24, 2009 18:31
Show Gist options
  • Save konklone/242092 to your computer and use it in GitHub Desktop.
Save konklone/242092 to your computer and use it in GitHub Desktop.
<!--
In your AndroidManifest.xml, designate the class that will handle creating a shortcut.
-->
<activity android:name=".CreateShortcut"
android:label="Name To Appear on the Shortcuts Menu"
>
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
// In the CreateShortcut activity, you want to create an Intent whose data has 3 special
// shortcut fields, as shown below: the intent to be launched when the shortcut is clicked,
// the text label, and the icon (which can be an icon ID from your drawables, or a Bitmap).
// Set it as the result of the Activity with the result code RESULT_OK.
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.your.package.name", "com.your.package.name.DestinationActivity");
// put whatever data the DestinationActivity needs, like the station
ID, into the intent
Parcelable shortcutIcon = Intent.ShortcutIconResource.fromContext(this, R.drawable.shortcut_icon);
// alternatively, you can make the shortcut icon a raw Bitmap
Intent shortcutData = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, shortcutIcon);
setResult(RESULT_OK, intent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment