compat/src/main/java/androidx/core/content/pm/ShortcutManagerCompat.java
public static boolean requestPinShortcut(@NonNull final Context context,
            @NonNull ShortcutInfoCompat shortcut, @Nullable final IntentSender callback) {
        if (Build.VERSION.SDK_INT >= 26) {
            return context.getSystemService(ShortcutManager.class).requestPinShortcut(
                    shortcut.toShortcutInfo(), callback);
        }

        if (!isRequestPinShortcutSupported(context)) {
            return false;
        }
        Intent intent = shortcut.addToIntent(new Intent(ACTION_INSTALL_SHORTCUT));

        // If the callback is null, just send the broadcast
        if (callback == null) {
            context.sendBroadcast(intent);
            return true;
        }

        // Otherwise send the callback when the intent has successfully been dispatched.
        context.sendOrderedBroadcast(intent, null, new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                try {
                    callback.sendIntent(context, 0, null, null, null);
                } catch (IntentSender.SendIntentException e) {
                    // Ignore
                }
            }
        }, null, Activity.RESULT_OK, null, null);
        return true;
    }
/**
     * Request to create a pinned shortcut.
     * <p>On API <= 25 it creates a legacy shortcut with the provided icon, label and intent. For
     * newer APIs it will create a {@link android.content.pm.ShortcutInfo} object which can be
     * updated by the app.
     *
     * <p>Use {@link android.app.PendingIntent#getIntentSender()} to create a {@link IntentSender}.
     *
     * @param shortcut new shortcut to pin
     * @param callback if not null, this intent will be sent when the shortcut is pinned
     *
     * @return {@code true} if the launcher supports this feature
     *
     * @see #isRequestPinShortcutSupported
     * @see IntentSender
     * @see android.app.PendingIntent#getIntentSender()
     */
Request to create a pinned shortcut.
On API <= 25 it creates a legacy shortcut with the provided icon, label and intent. For
newer APIs it will create a  android.content.pm.ShortcutInfo object which can be
updated by the app.



@param shortcut new shortcut to pin
@param callback if not null, this intent will be sent when the shortcut is pinned

@return  true if the launcher supports this feature


Request to create a pinned shortcut . On API < = 25 it creates a legacy shortcut with the provided icon label and intent . For newer APIs it will create a android . content . pm . ShortcutInfo object which can be updated by the app . @param shortcut new shortcut to pin @param callback if not null this intent will be sent when the shortcut is pinned @return true if the launcher supports this feature
public static boolean requestPinShortcut(@NonNull final Context context,
            @NonNull ShortcutInfoCompat shortcut, @Nullable final IntentSender callback) {
        if (Build.VERSION.SDK_INT >= 26) {
            return context.getSystemService(ShortcutManager.class).requestPinShortcut(
                    shortcut.toShortcutInfo(), callback);
        }
        if (!isRequestPinShortcutSupported(context)) {
            return false;
        }
        Intent intent = shortcut.addToIntent(new Intent(ACTION_INSTALL_SHORTCUT));
        if (callback == null) {
            context.sendBroadcast(intent);
            return true;
        }
        context.sendOrderedBroadcast(intent, null, new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                try {
                    callback.sendIntent(context, 0, null, null, null);
                } catch (IntentSender.SendIntentException e) {
                }
            }
        }, null, Activity.RESULT_OK, null, null);
        return true;
    }
public static boolean requestPinShortcut ( @ NonNull final Context context , @ NonNull ShortcutInfoCompat shortcut , @ Nullable final IntentSender callback ) { if ( Build . VERSION . SDK_INT >= 26 ) { return context . getSystemService ( ShortcutManager . class ) . requestPinShortcut ( shortcut . toShortcutInfo ( ) , callback ) ; } if ( ! isRequestPinShortcutSupported ( context ) ) { return false ; } Intent intent = shortcut . addToIntent ( new Intent ( ACTION_INSTALL_SHORTCUT ) ) ; if ( callback == null ) { context . sendBroadcast ( intent ) ; return true ; } context . sendOrderedBroadcast ( intent , null , new BroadcastReceiver ( ) { @ Override public void onReceive ( Context context , Intent intent ) { try { callback . sendIntent ( context , 0 , null , null , null ) ; } catch ( IntentSender . SendIntentException e ) { } } } , null , Activity . RESULT_OK , null , null ) ; return true ; }
Request to create a pinned shortcut.
Request to create a pinned shortcut .
// If the callback is null, just send the broadcast // Otherwise send the callback when the intent has successfully been dispatched. // Ignore