In my app I have a ListView when user click on an item some action is performed. Now I want to make a context menu for list item with possibility to add this action to home screen as a shortcut. Could somebody offer me some link or a hint how to do this?
问问题
544 次
1 回答
1
private void createShortcut(Command command){
Intent shortcutIntent = new Intent(this, FormActivity.class);
// As binary because OS does not know type Command
command.putToIntentAsXml(shortcutIntent);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, command.getTitle());
Parcelable iconResource = Intent
.ShortcutIconResource
.fromContext(this, R.drawable.ic_launcher);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
}
于 2011-02-06T14:10:47.647 回答