这是我用来创建快捷方式的工作代码:
Intent shortcutIntent = new Intent(ShortcutActivity.this, com.example.myproject.ClassToOpen.class);
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); // This was the line that I needed to add
ShortcutIconResource iconResource = Intent.ShortcutIconResource.fromContext(ShortcutActivity.this, R.drawable.shortcut);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name");
setResult(RESULT_OK, intent);