Android Question Create "Pinned" shortcuts?

JohnC

Expert
Licensed User
Longtime User
I would like to create a "Pinned" shortcut from *within* my app. A "pinned" shortcut is a shortcut that has an icon that is separate from the app's main icon on your homescreen.

Normally you can do this using the below method:

https://www.b4x.com/android/forum/t...y-from-within-your-application.17559/#content

But the above method doesn't work on Oreo (8.0+) devices as explained here:

https://developer.android.com/about/versions/oreo/android-8.0-changes#as

I do NOT want to create "Dynamic" shortcuts as explained in these two posts:

https://www.b4x.com/android/forum/threads/support-for-app-shortcuts.86663/#post-548645

https://www.b4x.com/android/forum/t...o-define-dynamic-shortcuts-android-7-1.87588/


So, I came across these posts on how to use the ShortcutManager to create "Pinned" shortcuts (which will ask the user for permission before placing the new shortcut on the homescreen/launcher:

https://stackoverflow.com/questions/6337431/android-create-shortcuts-on-the-home-screen

https://stackoverflow.com/questions/46796674/create-shortcut-on-home-screen-in-android-o

B4X:
if (ShortcutManagerCompat.isRequestPinShortcutSupported(context)) {
                final ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

                ShortcutInfo pinShortcutInfo = new ShortcutInfo.Builder(context, shortcutId)
                        .setIcon(Icon.createWithResource(context, R.mipmap.ic_launcher))
                        .setShortLabel(label)
                        .setIntent(new Intent(context, MainActivity.class).setAction(Intent.ACTION_MAIN))
                        .build();
                shortcutManager.requestPinShortcut(pinShortcutInfo, null);
            }
But, I am not very good at converting java code to work in B4A.

Any help to get this working would be greatly appreciated :)
 
Last edited:
Top