【问题标题】:Read data from Shortcut从快捷方式读取数据
【发布时间】:2017-10-22 02:41:26
【问题描述】:

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

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 到更高版本)。

谢谢。

【问题讨论】:

    标签: android android-intent android-shortcut android-shortcutmanager


    【解决方案1】:

    创建快捷方式一切正常

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

    只要单击该快捷方式,我就想读取此 user_id。

    把它作为额外的放在shortcutIntent

    【讨论】:

    • 效果很好。谢谢。另外,您能否说明一下它在 Android O 上无法运行的原因。
    • @SyedaZunairah:“com.android.launcher.action.INSTALL_SHORTCUT 广播不再对您的应用产生任何影响,因为它现在是私有的隐式广播。相反,您应该创建一个应用快捷方式通过使用 ShortcutManager 类中的 requestPinShortcut() 方法。” (来自the Android O release notes)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-14
    • 2018-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多