I’m making my own Android launcher and I want to react to requests from other apps to add a shortcut to home screen.
So far, I was only able to find out, that apps have to check if shortcut pinning is supported by calling isRequestPinShortcutSupported() from ShortcutManager and then send a request by calling requestPinShortcut() – but how do I implement the other side of that?
I don’t know how to tell ShortcutManager my launcher wants to receive these requests and where to handle them. I have tried registering various BroadcastReceivers but that wasn’t enough.
Only helpful thing I could find was LauncherApps.PinItemRequest, that can be created from Intent, but I can’t find how do I receive this intent.
Okay, I had to study android source code for this but I figured out I need to create an Activity like this:
<activity android:name=".Activities.AddShortcutActivity"> <intent-filter> <action android:name="android.content.pm.action.CONFIRM_PIN_SHORTCUT" /> </intent-filter> </activity>
And then in that Activity’s onCreate() I can call
LauncherApps().getPinItemRequest( this.getIntent() ); //handle request... this.finish();
and do whatever I need with that request. Hope this helps someone.