Looking at the code sample here - I find the following comment puzzling:
// ... We assume here that the
// app has implemented a method called createShortcutResultIntent() that
// returns a broadcast intent.
what does it mean the app has implemented ... where is this implementation done?
is it a broadcast receiver? registered to which intent filter?
is this an abstract method? of which class?
and then I see this code sample - which handles a completely different flow (I think) and I'm lost again
You can obtain feedback via catching the broadcast event which you setup while use
requestPinShortcut
function. At first you need a usual broadcast receiver (in the code below it has nameShortcutReceiver
). You can even use existing broadcast receiver and simple add new action which it should catch.Lets the action will be
"general.intent.action.SHORTCUT_ADDED"
and it will be stored inShortcutReceiver.kInstalledAction
constant. In this case in the manifest you should have:After this you can use following code in the activity for create a pinned shortcut (in other places change this on object of
Context
class):In this code
info
is correct object ofShortcutInfo
class.You can handle the event while catch the broadcast:
Please take into account that from my experience the broadcast event happens after the shortcut has been added but sometimes there can be some delays (at about some minutes). But may be there is some dependency on the launcher.
Update
As described in other answers on Android 8 catching of implicit intent via broadcast in general doesn't work. So I simple changed the intent to explicit via set package name of the current app. So only our broadcast receiver can catch the intent.