5

This is a short question:

Android Nougat 7.1 has a new feature for launchers, to create app-shortcuts by showing a menu to choose from them: https://developer.android.com/about/versions/nougat/android-7.1.html https://developer.android.com/guide/topics/ui/shortcuts.html

From what I see, if you use dynamic ones, you can put anything you wish into them, but can static shortcuts (those that are pre-determined via XML) have extras in them? Meaning: can I put, for example, a string in the bundle of the intent of shortcuts ? Or can I only choose which action each of them will have?

I ask this because I don't see it mentioned there.

android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • I'm not sure that there is documentation on what can all go in an `` element anywhere (e.g., in preference XML). – CommonsWare Jan 06 '17 at 21:18
  • @CommonsWare That's why I ask this. I can't find information about it. I hope it is possible, just because it gives a bit more flexibility. – android developer Jan 06 '17 at 21:40

1 Answers1

14

Yes, as per R.styleable#Intent:

Declaration of an Intent object in XML. May also include zero or more <categories> and <extra> tags.

Parsing the Intent can be seen in the Intent.parseIntent source code, where you'll see it parses the extra tags with Resources.parseBundleExtra(), which supports Strings, booleans, integers, and floats.

<intent android:action="YOUR_ACTION" >
     <extra android:name="extra_name" android:value="extra_value" />
</intent>
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • I just looked at the [ShortcutParser source code](https://android.googlesource.com/platform/frameworks/base/+/android-7.1.1_r4/services/core/java/com/android/server/pm/ShortcutParser.java#227) and tracked from there. – ianhanniballake Jan 06 '17 at 23:49
  • Seems to work well. Do you know of other interesting things about app-shortcuts? For example, when does "shortcutDisabledMessage" get used? And why if I put multiple static app-shortcuts, they are shown in opposite order? – android developer Jan 07 '17 at 13:55
  • The order is related to the launcher icon. The first shortcut declared will always appear next to the launcher icon. If the shortcut list appears above your launcher icon, the first declared shortcut will appear at bottom of the list, if the shortcut list appears below your launcher icon, the first declared shortcut will be at the top of the list. Hope it helps you! – Jonathan Aste Feb 05 '17 at 23:11
  • 1
    @JonathanAste - not necessarily. Launchers can display them in any order, although should attempt to sort them by their [rank](https://developer.android.com/reference/android/content/pm/ShortcutInfo.html#getRank()) and most generally break ties by using the order defined but they also could alpha sort them, etc – ianhanniballake Feb 06 '17 at 00:16