Example usage for android.support.v4.content.pm ShortcutManagerCompat isRequestPinShortcutSupported

List of usage examples for android.support.v4.content.pm ShortcutManagerCompat isRequestPinShortcutSupported

Introduction

In this page you can find the example usage for android.support.v4.content.pm ShortcutManagerCompat isRequestPinShortcutSupported.

Prototype

public static boolean isRequestPinShortcutSupported(@NonNull Context context) 

Source Link

Usage

From source file:org.mozilla.focus.shortcut.HomeScreen.java

/**
 * Create a shortcut via the AppCompat's shortcut manager.
 * <p>/*from   w  ww.j  av a  2  s .  co  m*/
 * On Android versions up to 7 shortcut will be created via system broadcast internally.
 * <p>
 * On Android 8+ the user will have the ability to add the shortcut manually
 * or let the system place it automatically.
 */
private static void installShortCutViaManager(Context context, Bitmap bitmap, String url, String title,
        boolean blockingEnabled) {
    if (ShortcutManagerCompat.isRequestPinShortcutSupported(context)) {
        final IconCompat icon = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
                ? IconCompat.createWithAdaptiveBitmap(bitmap)
                : IconCompat.createWithBitmap(bitmap);
        final ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(context,
                UUID.randomUUID().toString()).setShortLabel(title).setLongLabel(title).setIcon(icon)
                        .setIntent(createShortcutIntent(context, url, blockingEnabled)).build();
        ShortcutManagerCompat.requestPinShortcut(context, shortcut, null);
    }
}

From source file:com.amaze.filemanager.fragments.MainFragment.java

private void addShortcut(LayoutElementParcelable path) {
    //Adding shortcut for MainActivity
    //on Home screen
    final Context ctx = getContext();

    if (!ShortcutManagerCompat.isRequestPinShortcutSupported(ctx)) {
        Toast.makeText(getActivity(), getString(R.string.addshortcut_not_supported_by_launcher),
                Toast.LENGTH_SHORT).show();
        return;//from  www .  ja  v  a2s  .co m
    }

    Intent shortcutIntent = new Intent(ctx, MainActivity.class);
    shortcutIntent.putExtra("path", path.desc);
    shortcutIntent.setAction(Intent.ACTION_MAIN);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    // Using file path as shortcut id.
    ShortcutInfoCompat info = new ShortcutInfoCompat.Builder(ctx, path.desc)
            .setActivity(getMainActivity().getComponentName())
            .setIcon(IconCompat.createWithResource(ctx, R.mipmap.ic_launcher)).setIntent(shortcutIntent)
            .setLongLabel(path.desc).setShortLabel(new File(path.desc).getName()).build();

    ShortcutManagerCompat.requestPinShortcut(ctx, info, null);
}