Java 类android.support.v4.content.pm.ShortcutManagerCompat 实例源码

项目:transistor    文件:ShortcutHelper.java   
public void placeShortcut(Station station) {

        // credit: https://medium.com/@BladeCoder/using-support-library-26-0-0-you-can-do-bb75911e01e8
        if (ShortcutManagerCompat.isRequestPinShortcutSupported(mContext)) {
            ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(mContext, station.getStationName())
                    .setShortLabel(station.getStationName())
                    .setLongLabel(station.getStationName())
                    .setIcon(IconCompat.createWithBitmap(createShortcutIcon(station)))
                    .setIntent(createShortcutIntent(station))
                    .build();
            ShortcutManagerCompat.requestPinShortcut(mContext, shortcut, null);
            Toast.makeText(mContext, mContext.getString(R.string.toastmessage_shortcut_created), Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(mContext, mContext.getString(R.string.toastmessage_shortcut_not_created), Toast.LENGTH_LONG).show();
        }

    }
项目:firefox-tv    文件:HomeScreen.java   
/**
 * Create a shortcut via the AppCompat's shortcut manager.
 * <p>
 * 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);
    }
}
项目:focus-android    文件:HomeScreen.java   
/**
 * Create a shortcut via the AppCompat's shortcut manager.
 * <p>
 * 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);
    }
}
项目:SimplicityBrowser    文件:MainActivity.java   
private  void createShortcut(){
    Intent intent1 = new Intent(getApplicationContext(), MainActivity.class);
    intent1.setAction(Intent.ACTION_VIEW);
    intent1.setData(Uri.parse(mSearchView.getText().toString()));
    intent1.putExtra("duplicate", false);
    ShortcutInfoCompat pinShortcutInfo = new ShortcutInfoCompat.Builder(MainActivity.this, webViewTitle)
            .setShortLabel(webViewTitle)
            .setIcon(IconCompat.createWithBitmap(favoriteIcon))
            .setIntent(intent1)
            .build();
    ShortcutManagerCompat.requestPinShortcut(MainActivity.this, pinShortcutInfo, null);
}
项目:SimplicityBrowser    文件:MainActivity.java   
@Override
public void onCreateHomeScreenShortcut(AppCompatDialogFragment dialogFragment) {
    EditText shortcutNameEditText = dialogFragment.getDialog().findViewById(R.id.shortcut_name_edittext);
    Intent intent1 = new Intent(getApplicationContext(), MainActivity.class);
    intent1.setAction(Intent.ACTION_VIEW);
    intent1.setData(Uri.parse(mSearchView.getText().toString()));
    intent1.putExtra("duplicate", false);
    ShortcutInfoCompat pinShortcutInfo = new ShortcutInfoCompat.Builder(MainActivity.this, webViewTitle)
            .setShortLabel(shortcutNameEditText.getText().toString())
            .setIcon(IconCompat.createWithBitmap(StaticUtils.getCircleBitmap(favoriteIcon)))
            .setIntent(intent1)
            .build();
    ShortcutManagerCompat.requestPinShortcut(MainActivity.this, pinShortcutInfo, null);
}
项目:OpenLinkWith    文件:AddToHomeScreenDialogFragment.java   
private boolean createShortcutWith(String id, String label, IconCompat icon) {
    ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(getContext(), id)
            .setIntent(intent)
            .setShortLabel(label)
            .setIcon(icon)
            .build();
    return ShortcutManagerCompat.requestPinShortcut(getContext(), shortcut, startHomeScreen());
}
项目:AmazeFileManager    文件: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;
    }

    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);
}