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

ShortcutHelper.java 文件源码 项目:transistor 阅读 28 收藏 0 点赞 0 评论 0
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();
        }

    }
HomeScreen.java 文件源码 项目:firefox-tv 阅读 31 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
HomeScreen.java 文件源码 项目:focus-android 阅读 36 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
MainActivity.java 文件源码 项目:SimplicityBrowser 阅读 21 收藏 0 点赞 0 评论 0
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);
}
MainActivity.java 文件源码 项目:SimplicityBrowser 阅读 20 收藏 0 点赞 0 评论 0
@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);
}
AddToHomeScreenDialogFragment.java 文件源码 项目:OpenLinkWith 阅读 22 收藏 0 点赞 0 评论 0
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());
}
MainFragment.java 文件源码 项目:AmazeFileManager 阅读 39 收藏 0 点赞 0 评论 0
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);
}


问题


面经


文章

微信
公众号

扫码关注公众号