@LargeTest @Test @SdkSuppress(maxSdkVersion = 25) public void testRequestPinShortcut_v4_noCallback() throws Throwable { setMockPm(mockResolveInfo(null)); BlockingBroadcastReceiver receiver = new BlockingBroadcastReceiver(ShortcutManagerCompat.ACTION_INSTALL_SHORTCUT); assertTrue(ShortcutManagerCompat.requestPinShortcut(mContext, mInfoCompat, null)); verifyLegacyIntent(receiver.blockingGetIntent()); }
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; }
ShortcutManagerCompat { 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; } }
ShortcutManagerCompat { 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; } private  ShortcutManagerCompat(); }
ShortcutManagerCompat { 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; } private  ShortcutManagerCompat(); static boolean isRequestPinShortcutSupported(@NonNull Context context); static boolean requestPinShortcut(@NonNull final Context context,
            @NonNull ShortcutInfoCompat shortcut, @Nullable final IntentSender callback); @NonNull static Intent createShortcutResultIntent(@NonNull Context context,
            @NonNull ShortcutInfoCompat shortcut); }
ShortcutManagerCompat { 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; } private  ShortcutManagerCompat(); static boolean isRequestPinShortcutSupported(@NonNull Context context); static boolean requestPinShortcut(@NonNull final Context context,
            @NonNull ShortcutInfoCompat shortcut, @Nullable final IntentSender callback); @NonNull static Intent createShortcutResultIntent(@NonNull Context context,
            @NonNull ShortcutInfoCompat shortcut);  }