Android Question Support for app shortcuts?

bjf

Member
Licensed User
Longtime User
Hello.
I have tried searching but have not been able to find any info on this topic
Does B4A support app shortcuts, and if so how to use it?

android-71-app-shortcuts-100693489-large.jpg


Best regards
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Tools - Configure Paths - android.jar from API level 25+.

2. The shortcuts are defined in the manifest editor:
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.example3"
  android:targetClass="b4a.example3.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>
)
You need to replace b4a.example3 with your package name.

3. Code:
B4X:
Sub Process_Globals
   Private lastIntent As Intent   
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)

End Sub

Sub Activity_Resume
   If Activity.GetStartingIntent.IsInitialized Then
     If Activity.GetStartingIntent <> lastIntent Then
       lastIntent = Activity.GetStartingIntent
       If lastIntent.Action.StartsWith("b4a.shortcut.") Then
         Dim clickedItem As String = lastIntent.Action.SubString("b4a.shortcut.".Length)
         Log(clickedItem)
       End If
     End If
   End If
End Sub
 
Upvote 0
Top