从“快捷指令”读取数据



我使用此代码在我的应用程序中创建了活动的多个快捷方式

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);      

对于快捷方式创建来说一切正常,但我想从快捷方式或读取数据

每当单击该快捷方式时,我都想user_id阅读此内容

我不能把它放在SharedPreferences,因为它可以是多个快捷方式,每个快捷方式都链接到不同的user_id

我已经搜索过,到目前为止找不到任何东西。

在 android 7.0 之后,快捷方式得到了很大的改进,但我也必须让它也适用于较旧的设备(比如从 4 到以后(。

谢谢。

一切正常,可以创建快捷方式

FWIW,我认为它不适用于Android O。

每当单击该快捷方式时,我都想阅读此user_id。

把它作为额外的shortcutIntent.

最新更新