I am creating multiple shortcuts of an Activity in my application by using this code
Intent shortcutIntent = new Intent(getApplicationContext(), SingleChat.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Bitmap bm = ((BitmapDrawable)contact_image.getDrawable()).getBitmap();
Bitmap bti = Bitmap.createScaledBitmap(bm, 120, 120, false);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra("user_id", csUserId);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, csUserName);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bti);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
Everything is working perfectly fine for shortcut creation but I want to read the data from the shortcut OR
I want to read this user_id
whenever that shortcut is clicked.
I can't put it in SharedPreferences
as it can be more than one shortcuts each linking to different user_id
.
I have searched and so far couldn't find anything.
Shortcuts have been improved quite a lot after android 7.0 but I have to make it working for older devices too (say from 4 to onward).
Thanks.
FWIW, I don't think it will work on Android O.
Put it as an extra in
shortcutIntent
.