【发布时间】:2012-04-19 21:28:00
【问题描述】:
我正在尝试在主屏幕上为我的应用程序内的活动创建快捷方式。 我设法创建了快捷方式,但是当我点击它时什么也没有发生,它说“找不到应用程序” 这是我的代码的样子:
final Intent shortcutIntent = new Intent("com.myapp.action.MyActivity");
ComponentName name = new ComponentName(getPackageName(), ".MyActivity");
shortcutIntent.setComponent(name);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "blabla..");
Parcelable iconResource =
Intent.ShortcutIconResource.fromContext(PresetsActivity.this,R.drawable.ic_application_launcher);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,iconResource);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
【问题讨论】: