I am trying to pass data with the shortcut that is created when the user clicks on a button. So that when the user runs the application through that specific shortcut the MainActivity
receivers that data and perform decision on that data.
For example, I want to pass the URL of the website. If the user clicks Button 1 the URL for that shortcut will be "http://expample1.com" and if Button 2 is clicked a new shortcut will be created with second URL "http://expample2.com".
I looked through other question but they only about creating a shortcut. Another method I came across is using ShortcutManager
but it only supports API level 25
above.
This is the code to create a shortcut that I wrote. Now how can I add data in it for use?
public void onBtnSecondShortCutCreate(View view) {
Intent shortcutIntent = new Intent(getApplicationContext(), SecondActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra("SecondMessage","Second Activity");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "beSpider Second app");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.logo));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}