3
ホーム画面でユーザが押したショートカットに基づいて異なるコンテンツを表示するアクティビティがあります。ショートカットを作成するためのインテントによる1つのアクティビティのマルチショートカットの作成
のAndroidManifest.xml
<activity
android:name=".activities.ShortcutActivity_"
android:parentActivityName=".activities.MainActivity_"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
方法:
マイコードはこのようになります
private void createShortcut(String label){
Intent shortcut = new Intent(getApplicationContext(), ShortcutActivity_.class);
shortcut.setAction(Intent.ACTION_MAIN);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.mipmap.ic_launcher));
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra("duplicate", false);
getApplicationContext().sendBroadcast(intent);
}
私はこのようなメソッドを呼び出しています:
createShortcut(ShortcutActivity_.class, "Shortcut 1");
createShortcut(ShortcutActivity_.class, "Shortcut 2");
私の活動では、ラベルをチェックし、ショートカットごとに異なる内容を表示したいが、機能しません。ショートカットは1つだけ作成されます。
押されたショートカットに基づいて異なるコンテンツを表示できる動的なアクティビティを作成するにはどうすればよいですか?
ご協力いただきありがとうございます。