Example usage for android.support.v4.graphics.drawable IconCompat createWithBitmap

List of usage examples for android.support.v4.graphics.drawable IconCompat createWithBitmap

Introduction

In this page you can find the example usage for android.support.v4.graphics.drawable IconCompat createWithBitmap.

Prototype

public static IconCompat createWithBitmap(Bitmap bits) 

Source Link

Document

Create an Icon pointing to a bitmap in memory.

Usage

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

/**
 * Create a shortcut via the AppCompat's shortcut manager.
 * <p>/*  w ww .  j  a  v  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);
    }
}