This Library help you to define dynamic shortcuts for your app.
A Device with Android 7.1 (Api 25) is needed to use this library.
ShortcutHelper
Author: DonManfred
Version: 1.0
The Shortcuts can be added fix in the manifest.
See this example @Erel provided.
Please note that it is NOT mandatory to define the Shortcuts in the Manifest. They can be fully dynamically created.
BUT: Shortcuts defined in the Manifest will be available for your app directly if you install the app.
The dynamically added are only shown after you FIRST START the app (note that the Dynamics are created in Activity_create).
So i suggest to use them both.
Fixed Shortcuts in Manifest + Dynamics added with this library.
A Device with Android 7.1 (Api 25) is needed to use this library.
ShortcutHelper
Author: DonManfred
Version: 1.0
- ShortcutHelper
- Functions:
- addDynamicShortcuts (shortcutInfoList As List) As Boolean
- createShortcut (shortLabel As CharSequence, longLabel As CharSequence, IconResource As String, intent As android.content.Intent) As android.content.pm.ShortcutInfo
- disableShortcuts (shortcuts2disable As List, disabledMessage As CharSequence)
- disableShortcuts2 (shortcuts2disable As List)
- enableShortcuts (shortcuts2enable As List)
- Initialize (EventName As String)
- isRateLimitingActive As Boolean
- removeAllDynamicShortcuts
- removeDynamicShortcuts (shortcutIds As List)
- reportShortcutUsed (shortcutId As String)
- setDynamicShortcuts (dynamicShortcuts As List) As Boolean
- updateShortcuts (shortcuts2update As List) As Boolean
- addDynamicShortcuts (shortcutInfoList As List) As Boolean
- Properties:
- DynamicShortcuts As List [read only]
- IconMaxHeight As Int [read only]
- IconMaxWidth As Int [read only]
- ManifestShortcuts As List [read only]
- MaxShortcutCountPerActivity As Int [read only]
- PinnedShortcuts As List [read only]
- DynamicShortcuts As List [read only]
- Functions:
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim helper As ShortcutHelper
Dim cs As CSBuilder
Dim pm As PackageManager
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
helper.Initialize("")
Log(helper.ManifestShortcuts)
Dim dynshortcuts As List
dynshortcuts.Initialize
Dim in As Intent
in = pm.GetApplicationIntent(Application.PackageName)
in.AddCategory("dynamic")
in.PutExtra("menu1","HelloWorld")
dynshortcuts.Add(helper.createShortcut(cs.Initialize.Color(Colors.Red).Append("Hello World!").PopAll,cs.Initialize.Color(Colors.Blue).Append("This is the long label").PopAll,"ic_action_achievement",in))
Dim in As Intent
in = pm.GetApplicationIntent(Application.PackageName)
in.AddCategory("dynamic")
in.PutExtra("menu2","dynamic2")
dynshortcuts.Add(helper.createShortcut(cs.Initialize.Color(Colors.Red).Append("2nd dynamic").PopAll,cs.Initialize.Color(Colors.Blue).Append("This is the long label").PopAll,"ic_action_amazon",in))
Dim in As Intent
in = pm.GetApplicationIntent(Application.PackageName)
in.AddCategory("dynamic")
in.PutExtra("menu3","dynamic3")
dynshortcuts.Add(helper.createShortcut(cs.Initialize.Color(Colors.Red).Append("3rd dynamic").PopAll,cs.Initialize.Color(Colors.Blue).Append("This is the long label").PopAll,"ic_action_armchair",in))
helper.setDynamicShortcuts(dynshortcuts)
The Shortcuts can be added fix in the manifest.
See this example @Erel provided.
B4X:
AddActivityText(main, <meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
)
CreateResource(xml, shortcuts.xml,
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="compose"
android:enabled="true"
android:icon="@drawable/icon"
android:shortcutShortLabel="@string/compose_shortcut_short_label1"
android:shortcutLongLabel="@string/compose_shortcut_long_label1"
android:shortcutDisabledMessage="@string/compose_disabled_message1">
<intent
android:action="b4a.shortcut.item1"
android:targetPackage="b4a.example.shortcut"
android:targetClass="b4a.example.shortcut.main" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
<!-- Specify more shortcuts here. -->
</shortcuts>
)
CreateResource(values, strings.xml,
<resources>
<string name="compose_shortcut_short_label1">short label</string>
<string name="compose_shortcut_long_label1">long label</string>
<string name="compose_disabled_message1">disabled</string>
</resources>
)
Please note that it is NOT mandatory to define the Shortcuts in the Manifest. They can be fully dynamically created.
BUT: Shortcuts defined in the Manifest will be available for your app directly if you install the app.
The dynamically added are only shown after you FIRST START the app (note that the Dynamics are created in Activity_create).
So i suggest to use them both.
Fixed Shortcuts in Manifest + Dynamics added with this library.
Attachments
Last edited: