Java 类android.content.pm.ShortcutInfo 实例源码

项目:Android-O-Feature    文件:PinningActivity.java   
private void pinShortcutToHomeScreen(Context context) {
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    if (shortcutManager.isRequestPinShortcutSupported()) {
        ShortcutInfo pinShortcutInfo = createShortcutInfo(this);
        Intent resultIntent = shortcutManager.createShortcutResultIntent(pinShortcutInfo);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, resultIntent, 0);
        shortcutManager.requestPinShortcut(pinShortcutInfo, pendingIntent.getIntentSender());
    } else {
        Toast.makeText(context, R.string.device_does_not_support_shortcut_pinning, Toast.LENGTH_SHORT).show();
    }
}
项目:Loyalty    文件:LauncherInfoManager.java   
/**
 * Update the dynamic shortcuts that are associated with this app. The given list of cards must
 * be sorted by popularity. The amount parameter indicates how much shortcuts should be made.
 *
 * @param cards A list of cards that's sorted by popularity.
 * @param amount Amount indicates the number n of cards for which a shortcut should be made from
 *               the list.
 */
public void updateDynamicShortcuts(List<Card> cards, int amount) {
    if (cards.size() < amount) {
        amount = cards.size();
    }

    this.cards = cards;

    List<ShortcutInfo> shortcuts = new ArrayList<>();

    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);


    for (int i = 0; i < amount; i++) {
        ShortcutInfo shortcut = new ShortcutInfo.Builder(context, cards.get(i).getName() + "-shortcut")
                .setShortLabel(cards.get(i).getName())
                .setIcon(Icon.createWithResource(context, R.drawable.shortcut_store))
                .setIntent(createCardShortcutIntent(cards.get(i)))
                .build();
        shortcuts.add(shortcut);
    }

    shortcutManager.setDynamicShortcuts(shortcuts);
}
项目:Wake    文件:WakeActivity.java   
@TargetApi(Build.VERSION_CODES.N_MR1)
private void createShortcut(String label, String packageName, Bitmap icon, Intent intent) {
    ShortcutManager shortcutManager;
    shortcutManager = getSystemService(ShortcutManager.class);

    ShortcutInfo shortcut = new ShortcutInfo.Builder(this, packageName)
            .setShortLabel(label)
            .setLongLabel(label)
            .setIcon(Icon.createWithBitmap(icon))
            .setIntent(intent)
            .setRank(0)
            .build();

    List<ShortcutInfo> shortcutList = shortcutManager.getDynamicShortcuts();
    int shortcutSize = shortcutList.size();

    if (shortcutSize >= 5) {
        for (int i = 0; i < shortcutSize - 4; i++) {
            shortcutManager.removeDynamicShortcuts(Collections.singletonList(shortcutList.get(0).getId()));
        }
    }
    shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut));
}
项目:CurrentActivity    文件:SplashActivity.java   
@TargetApi(Build.VERSION_CODES.N_MR1)
private void createShortcut() {
    ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

    Intent intent = new Intent(this, SplashActivity.class);
    intent.setAction(ACTION_QUICK_START_OR_QUICK_STOP);
    intent.putExtra(EXTRA_COME_FROM_SHORTCUT, true);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

    ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "shortcut_quick_switch")
            .setShortLabel(getString(R.string.shortcut_quick_switch))
            .setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
            .setIntent(intent)
            .build();

    if (shortcutManager != null) {
        shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
    }
}
项目:shortcut-helper    文件:ShortcutHelper.java   
public ShortcutHelper createShortcutList(@NonNull List<Shortcut> shortcuts) {
    if (Build.VERSION.SDK_INT < 25) {
        return this;
    }
    mShortcutManager = mActivity.getSystemService(ShortcutManager.class);
    for (int i=0; i<shortcuts.size(); i++) {
        if (i < mShortcutManager.getMaxShortcutCountPerActivity()) {
            String shortcutId = shortcuts.get(i).getShortLabel().replaceAll("\\s+","").toLowerCase() + "_shortcut";
            ShortcutInfo shortcut = new ShortcutInfo.Builder(mActivity, shortcutId)
                    .setShortLabel(shortcuts.get(i).getShortLabel())
                    .setLongLabel(shortcuts.get(i).getLongLabel())
                    .setIcon(Icon.createWithResource(mActivity, shortcuts.get(i).getIconResource()))
                    .setIntent(shortcuts.get(i).getIntent())
                    .build();
            mShortcutInfos.add(shortcut);
        }
    }
    return this;
}
项目:shortbread    文件:ShortbreadGenerated.java   
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    if (shortcuts == null) {
        List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
        List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
        enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
                .setShortLabel("Short label")
                .setIntents(TaskStackBuilder.create(context)
                        .addNextIntent(new Intent(Intent.ACTION_VIEW))
                        .getIntents())
                .setRank(0)
                .build());

        shortcuts = Arrays.asList(enabledShortcuts, disabledShortcuts);
    }

    return shortcuts;
}
项目:shortbread    文件:ResourcesShortcutActivityGenerated.java   
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(context.getString(34))
            .setLongLabel(context.getString(56))
            .setIcon(Icon.createWithResource(context, 12))
            .setDisabledMessage(context.getString(78))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(ResourcesShortcutActivity.class)
                    .addNextIntent(new Intent(context, ResourcesShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
项目:shortbread    文件:BackStackShortcutActivityGenerated.java   
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel("SHORT_LABEL")
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(BackStackShortcutActivity.class)
                    .addNextIntent(new Intent(Intent.ACTION_VIEW).setClass(context, EmptyActivity1.class))
                    .addNextIntent(new Intent(Intent.ACTION_VIEW).setClass(context, EmptyActivity2.class))
                    .addNextIntent(new Intent(context, BackStackShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
项目:shortbread    文件:TwoShortcutActivitiesGenerated.java   
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, SimpleShortcutActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(SimpleShortcutActivity.class)
                    .addNextIntent(new Intent(context, SimpleShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID_2")
            .setShortLabel("SHORT_LABEL")
            .setLongLabel("LONG_LABEL")
            .setIcon(Icon.createWithResource(context, 123))
            .setDisabledMessage("DISABLED_MESSAGE")
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(AdvancedShortcutActivity.class)
                    .addNextIntent(new Intent(context, AdvancedShortcutActivity.class)
                            .setAction("ACTION"))
                    .getIntents())
            .setRank(1)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
项目:shortbread    文件:AdvancedShortcutActivityGenerated.java   
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID_2")
            .setShortLabel("SHORT_LABEL")
            .setLongLabel("LONG_LABEL")
            .setIcon(Icon.createWithResource(context, 123))
            .setDisabledMessage("DISABLED_MESSAGE")
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(AdvancedShortcutActivity.class)
                    .addNextIntent(new Intent(context, AdvancedShortcutActivity.class)
                            .setAction("ACTION"))
                    .getIntents())
            .setRank(1)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
项目:shortbread    文件:TwoMethodShortcutActivitiesGenerated.java   
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, MethodShortcutActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(MethodShortcutActivity.class)
                    .addNextIntent(new Intent(context, MethodShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod"))
                    .getIntents())
            .setRank(0)
            .build());
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, MethodShortcutActivity2.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(MethodShortcutActivity2.class)
                    .addNextIntent(new Intent(context, MethodShortcutActivity2.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod"))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
项目:shortbread    文件:TwoMethodShortcutsActivityGenerated.java   
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, TwoMethodShortcutsActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(TwoMethodShortcutsActivity.class)
                    .addNextIntent(new Intent(context, TwoMethodShortcutsActivity.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod1"))
                    .getIntents())
            .setRank(0)
            .build());
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID_2")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, TwoMethodShortcutsActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(TwoMethodShortcutsActivity.class)
                    .addNextIntent(new Intent(context, TwoMethodShortcutsActivity.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod2"))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
项目:shortstories    文件:ChoiceActivity.java   
private void addChoiceShortcuts() {
    ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
    if (mChoice.isFinish()) {
        shortcutManager.removeAllDynamicShortcuts();
        return;
    }
    if (mChoice.choices == null || mChoice.choices.size() == 0) {
        return;
    }
    List<ShortcutInfo> choiceShortcuts = new ArrayList<>();
    int rank = 1;
    for (Choice choice : mChoice.choices) {
        ShortcutInfo choiceShortcut = new ShortcutInfo.Builder(this, IdUtil.getRandomUniqueShortcutId())
                .setShortLabel(choice.action)
                .setLongLabel(choice.action)
                .setDisabledMessage(getString(R.string.shortcut_disabled_message))
                .setIcon(Icon.createWithBitmap(choice.getActionEmoji(this)))
                .setIntent(IntentUtil.choice(this, choice))
                .setRank(rank)
                .build();
        choiceShortcuts.add(choiceShortcut);
        rank++;
    }
    shortcutManager.setDynamicShortcuts(choiceShortcuts);
}
项目:shortrain    文件:ShortcutsUtils.java   
public static int getNextRailNumber(ShortcutManager shortcutManager) {
    List<ShortcutInfo> shortcuts = shortcutManager.getPinnedShortcuts();

    int newRailId = -1;

    for (ShortcutInfo shortcutInfo : shortcuts) {
        String id = shortcutInfo.getId();
        if (isRailShortcut(id)) {
            int railId = getRailNumber(id);
            if (railId > newRailId) {
                newRailId = railId;
            }
        }
    }

    newRailId++;

    return newRailId;
}
项目:StopApp    文件:ShortcutsManager.java   
/**
 * 添加App Shortcut
 */
public void addAppShortcut(List<AppInfo> appList) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        List<AppInfo> appInfoDB = new ArrayList<>(
                mDBController.getDisableApps(AppInfoDBOpenHelper.TABLE_NAME_SHORTCUT_APP_INFO));

        for (AppInfo appInfo : appList) {
            if (!mDBController.searchApp(AppInfoDBOpenHelper.TABLE_NAME_SHORTCUT_APP_INFO, appInfo.getAppPackageName())) {
                appInfoDB.add(appInfo);
            }
        }

        mDBController.clearDisableApp(AppInfoDBOpenHelper.TABLE_NAME_SHORTCUT_APP_INFO);
        List<ShortcutInfo> shortcutList = new ArrayList<>();
        for (int i = appInfoDB.size() - 1; i >= 0; i--) {
            if (shortcutList.size() < 4) {
                shortcutList.add(getShortcut(appInfoDB.get(i)));
                mDBController.addDisableApp(appInfoDB.get(i), AppInfoDBOpenHelper.TABLE_NAME_SHORTCUT_APP_INFO);
            } else {
                removeShortcut(appInfoDB.get(i).getAppPackageName(), mContext.getString(R.string.shortcut_num_limit));
            }
        }
        mShortcutManager.setDynamicShortcuts(shortcutList);
    }
}
项目:StopApp    文件:ShortcutsManager.java   
/**
     * 构造App Shortcut Intent
     *
     * @param appInfo
     * @return
     */
    private ShortcutInfo getShortcut(AppInfo appInfo) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
            ShortcutInfo shortcut = new ShortcutInfo.Builder(mContext, appInfo.getAppPackageName())
                    .setShortLabel(appInfo.getAppName())
                    .setIcon(Icon.createWithBitmap(appInfo.getAppIcon()))
                    .setIntent(
                            new Intent(ShortcutActivity.OPEN_APP_SHORTCUT)
                                    .putExtra(ShortcutActivity.EXTRA_PACKAGE_NAME, appInfo.getAppPackageName())
                            // this dynamic shortcut set up a back stack using Intents, when pressing back, will go to MainActivity
                            // the last Intent is what the shortcut really opened
//                            new Intent[]{
//                                    new Intent(Intent.ACTION_MAIN, Uri.EMPTY, mContext, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK),
//                                    new Intent(AppListActivity.ACTION_OPEN_DYNAMIC)
//                                    // intent's action must be set
//                            }
                    )
                    .build();

            return shortcut;
        } else {
            return null;
        }
    }
项目:MusicX-music-player    文件:ShortcutsHandler.java   
/**
 * Shortucts features on android N
 * @param context
 */
public static void create(Context context) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
        ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
        Icon pause = Icon.createWithResource(context, R.drawable.ic_shortcut_aw_ic_pause);
        ShortcutInfo pauses = new ShortcutInfo.Builder(context, Constants.PAUSE_SHORTCUTS)
                .setShortLabel("Pause")
                .setIcon(pause)
                .setIntent(shortcut(context,2))
                .build();

        Icon play = Icon.createWithResource(context, R.drawable.ic_shortcut_aw_ic_play);
        ShortcutInfo plays = new ShortcutInfo.Builder(context, Constants.PLAY_SHORTCUTS)
                .setShortLabel("Play")
                .setIcon(play)
                .setIntent(shortcut(context, 1))
                .build();
        ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
        shortcuts.add(plays);
        shortcuts.add(pauses);
        shortcutManager.setDynamicShortcuts(shortcuts);
    }
}
项目:FlickLauncher    文件:DeepShortcutManagerN.java   
@Override
protected List<ShortcutInfoCompat> query(int flags, String packageName, ComponentName componentName, List<String> shortcutIds, UserHandle userHandle) {
    List<ShortcutInfo> shortcuts = null;
    ShortcutQuery shortcutQuery = new ShortcutQuery();
    shortcutQuery.setQueryFlags(flags);
    if (packageName != null) {
        shortcutQuery.setPackage(packageName);
        shortcutQuery.setActivity(componentName);
        shortcutQuery.setShortcutIds(shortcutIds);
    }
    try {
        shortcuts = mLauncherApps.getShortcuts(shortcutQuery, userHandle);
        mWasLastCallSuccess = true;
    } catch (Throwable e) {
        Log.e("DeepShortcutManager", "Failed to query for shortcuts", e);
        mWasLastCallSuccess = false;
    }
    if (shortcuts == null) {
        return Collections.emptyList();
    }
    List<ShortcutInfoCompat> shortcutList = new ArrayList<>(shortcuts.size());
    for (ShortcutInfo shortcutInfoCompat : shortcuts) {
        shortcutList.add(new ShortcutInfoCompat(shortcutInfoCompat));
    }
    return shortcutList;
}
项目:Daedalus    文件:Daedalus.java   
public static void updateShortcut(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        Log.d("Daedalus", "Updating shortcut");
        //shortcut!
        String notice = context.getString(R.string.button_text_activate);
        boolean activate = true;
        ActivityManager manager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
        for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
            if (DaedalusVpnService.class.getName().equals(service.service.getClassName())) {
                notice = context.getString(R.string.button_text_deactivate);
                activate = false;
            }
        }
        ShortcutInfo info = new ShortcutInfo.Builder(context, Daedalus.SHORTCUT_ID_ACTIVATE)
                .setLongLabel(notice)
                .setShortLabel(notice)
                .setIcon(Icon.createWithResource(context, R.mipmap.ic_launcher))
                .setIntent(new Intent(context, MainActivity.class).setAction(Intent.ACTION_VIEW)
                        .putExtra(MainActivity.LAUNCH_ACTION, activate ? MainActivity.LAUNCH_ACTION_ACTIVATE : MainActivity.LAUNCH_ACTION_DEACTIVATE))
                .build();

        ShortcutManager shortcutManager = (ShortcutManager) context.getSystemService(SHORTCUT_SERVICE);
        shortcutManager.addDynamicShortcuts(Collections.singletonList(info));
    }
}
项目:RespawnIRC-Android    文件:Utils.java   
@TargetApi(25)
public static void updateShortcuts(Activity parentActivity, ShortcutManager shortcutManager, int sizeOfForumFavArray) {
    ArrayList<ShortcutInfo> listOfShortcuts = new ArrayList<>();
    int sizeOfShortcutArray = (sizeOfForumFavArray > 4 ? 4 : sizeOfForumFavArray);

    for (int i = 0; i < sizeOfShortcutArray; ++i) {
        String currentShortcutLink = PrefsManager.getStringWithSufix(PrefsManager.StringPref.Names.FORUM_FAV_LINK, String.valueOf(i));
        String currentShortcutName = PrefsManager.getStringWithSufix(PrefsManager.StringPref.Names.FORUM_FAV_NAME, String.valueOf(i));
        ShortcutInfo newShortcut = new ShortcutInfo.Builder(parentActivity, String.valueOf(i) + "_" + currentShortcutLink)
                .setShortLabel(currentShortcutName)
                .setLongLabel(currentShortcutName)
                .setIcon(Icon.createWithResource(parentActivity, R.mipmap.ic_shortcut_forum))
                .setIntent(new Intent(MainActivity.ACTION_OPEN_LINK, Uri.parse(currentShortcutLink))).build();

        listOfShortcuts.add(newShortcut);
    }

    try {
        shortcutManager.setDynamicShortcuts(listOfShortcuts);
    } catch (Exception e) {
        /* À ce qu'il parait ça peut crash "when the user is locked", je sais pas ce que ça
         * veut dire donc dans le doute je mets ça là. */
    }
}
项目:Android7_Shortcuts_Demo    文件:MainActivity.java   
private void setupShortcuts() {
        mShortcutManager = getSystemService(ShortcutManager.class);

        List<ShortcutInfo> infos = new ArrayList<>();
        for (int i = 0; i < mShortcutManager.getMaxShortcutCountPerActivity(); i++) {
            Intent intent = new Intent(this, MessageActivity.class);
            intent.setAction(Intent.ACTION_VIEW);
            intent.putExtra("msg", "我和" + mAdapter.getItem(i) + "的对话");

            ShortcutInfo info = new ShortcutInfo.Builder(this, "id" + i)
                    .setShortLabel(mAdapter.getItem(i))
                    .setLongLabel("联系人:" + mAdapter.getItem(i))
                    .setIcon(Icon.createWithResource(this, R.drawable.icon))
                    .setIntent(intent)
                    .build();
            infos.add(info);
//            manager.addDynamicShortcuts(Arrays.asList(info));
        }

        mShortcutManager.setDynamicShortcuts(infos);
    }
项目:zapp    文件:ShortcutHelper.java   
/**
 * Adds the given channel as shortcut to the launcher icon.
 * Only call on api level >= 25.
 *
 * @param context to access system services
 * @param channel channel to create a shortcut for
 * @return true if the channel could be added
 */
@TargetApi(25)
public static boolean addShortcutForChannel(Context context, ChannelModel channel) {
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);

    if (shortcutManager == null || shortcutManager.getDynamicShortcuts().size() >= 4) {
        return false;
    }

    ShortcutInfo shortcut = new ShortcutInfo.Builder(context, channel.getId())
        .setShortLabel(channel.getName())
        .setLongLabel(channel.getName())
        .setIcon(Icon.createWithResource(context, channel.getDrawableId()))
        .setIntent(ChannelDetailActivity.getStartIntent(context, channel.getId()))
        .build();

    try {
        return shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut));
    } catch (IllegalArgumentException e) {
        // too many shortcuts
        return false;
    }
}
项目:AppOpsX    文件:Helper.java   
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private static void updataShortcuts(Context context, List<AppInfo> items) {
  ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
  List<ShortcutInfo> shortcutInfoList = new ArrayList<>();
  int max = shortcutManager.getMaxShortcutCountPerActivity();
  for (int i = 0; i < max && i < items.size(); i++) {
    AppInfo appInfo = items.get(i);
    ShortcutInfo.Builder shortcut = new ShortcutInfo.Builder(context, appInfo.packageName);
    shortcut.setShortLabel(appInfo.appName);
    shortcut.setLongLabel(appInfo.appName);

    shortcut.setIcon(
        Icon.createWithBitmap(drawableToBitmap(LocalImageLoader.getDrawable(context, appInfo))));

    Intent intent = new Intent(context, AppPermissionActivity.class);
    intent.putExtra(AppPermissionActivity.EXTRA_APP_PKGNAME, appInfo.packageName);
    intent.putExtra(AppPermissionActivity.EXTRA_APP_NAME, appInfo.appName);
    intent.setAction(Intent.ACTION_DEFAULT);
    shortcut.setIntent(intent);

    shortcutInfoList.add(shortcut.build());
  }
  shortcutManager.setDynamicShortcuts(shortcutInfoList);
}
项目:loyalty-card-locker    文件:ShortcutHelper.java   
/**
 * Remove the given card id from the app shortcuts, if such a
 * shortcut exists.
 */
@TargetApi(25)
static void removeShortcut(Context context, int cardId)
{
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1)
    {
        ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
        List<ShortcutInfo> list = shortcutManager.getDynamicShortcuts();

        String shortcutId = Integer.toString(cardId);

        for(int index = 0; index < list.size(); index++)
        {
            if(list.get(index).getId().equals(shortcutId))
            {
                list.remove(index);
                break;
            }
        }

        shortcutManager.setDynamicShortcuts(list);
    }
}
项目:AndroidFileHost_Browser    文件:MainActivity.java   
@Override
public void setShortcut(String did, String manufacturer, String deviceName) {
    //Home screen shortcut for favourite device

    if (Build.VERSION.SDK_INT < 25)
        return;
    ShortcutManager sM = getSystemService(ShortcutManager.class);
    sM.removeAllDynamicShortcuts();

    Intent intent = new Intent(getApplicationContext(), MainActivity.class);
    intent.setAction(Intent.ACTION_VIEW);
    intent.putExtra(Constants.EXTRA_DEVICE_ID, did);

    ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "shortcut1")
            .setIntent(intent)
            .setLongLabel(manufacturer + " " + deviceName)
            .setShortLabel(deviceName)
            .setIcon(Icon.createWithResource(this, R.drawable.ic_device_placeholder))
            .build();
    sM.setDynamicShortcuts(Collections.singletonList(shortcut));
}
项目:HelloNougat    文件:MainActivity.java   
@TargetApi(25)
private void updateDynamicShortcuts() {
    ShortcutInfo webShortcut = new ShortcutInfo.Builder(MainActivity.this, "shortcut_blog")
            .setRank(1)
            .build();

    ShortcutInfo dynamicShortcut = new ShortcutInfo.Builder(MainActivity.this, "shortcut_dynamic")
            .setRank(0)
            .build();
    // the rank value can not be set to negative, otherwise will throw
    // java.lang.IllegalArgumentException: Rank cannot be negative or bigger than MAX_RANK

    // the static shortcuts have the rank 0, so they will always be closest to launcher icon

    shortcutManager.updateShortcuts(Arrays.asList(webShortcut, dynamicShortcut));
}
项目:android-proguards    文件:ShortcutHelper.java   
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void enablePostShortcut(@NonNull Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);

    Intent intent = new Intent(context, PostNewDesignerNewsStory.class);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    ShortcutInfo postShortcut
            = new ShortcutInfo.Builder(context, POST_SHORTCUT_ID)
            .setShortLabel(context.getString(R.string.shortcut_post_short_label))
            .setLongLabel(context.getString(R.string.shortcut_post_long_label))
            .setDisabledMessage(context.getString(R.string.shortcut_post_disabled))
            .setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_post))
            .setIntent(intent)
            .build();
    shortcutManager.addDynamicShortcuts(Collections.singletonList(postShortcut));
}
项目:SpotiQ    文件:ShortcutUtil.java   
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
public static void addSearchShortcut(Context context, String searchWithPartyTitle) {
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);

    Intent openSearch = new Intent(context.getApplicationContext(), SearchActivity.class);
    openSearch.putExtra(ApplicationConstants.PARTY_NAME_EXTRA, searchWithPartyTitle);
    openSearch.setAction(Intent.ACTION_VIEW);

    ShortcutInfo shortcut = new ShortcutInfo.Builder(context, ApplicationConstants.SEARCH_SHORTCUT_ID)
        .setShortLabel("Search songs")
        .setLongLabel("Search for songs to add to the queue")
        .setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_search))
        .setIntent(openSearch)
        .build();

    shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));
}
项目:365browser    文件:LauncherShortcutActivity.java   
/**
 * Adds a "New incognito tab" dynamic launcher shortcut.
 * @param context The context used to retrieve the system {@link ShortcutManager}.
 * @return True if addint the shortcut has succeeded. False if the call fails due to rate
 *         limiting. See {@link ShortcutManager#addDynamicShortcuts}.
 */
@TargetApi(Build.VERSION_CODES.N_MR1)
private static boolean addIncognitoLauncherShortcut(Context context) {
    Intent intent = new Intent(LauncherShortcutActivity.ACTION_OPEN_NEW_INCOGNITO_TAB);
    intent.setPackage(context.getPackageName());
    intent.setClass(context, LauncherShortcutActivity.class);

    ShortcutInfo shortcut =
            new ShortcutInfo.Builder(context, DYNAMIC_OPEN_NEW_INCOGNITO_TAB_ID)
                    .setShortLabel(context.getResources().getString(
                            R.string.accessibility_tabstrip_incognito_identifier))
                    .setLongLabel(
                            context.getResources().getString(R.string.menu_new_incognito_tab))
                    .setIcon(Icon.createWithResource(context, R.drawable.shortcut_incognito))
                    .setIntent(intent)
                    .build();

    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    return shortcutManager.addDynamicShortcuts(Arrays.asList(shortcut));
}
项目:plaid    文件:ShortcutHelper.java   
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void enablePostShortcut(@NonNull Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);

    Intent intent = new Intent(context, PostNewDesignerNewsStory.class);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    ShortcutInfo postShortcut
            = new ShortcutInfo.Builder(context, POST_SHORTCUT_ID)
            .setShortLabel(context.getString(R.string.shortcut_post_short_label))
            .setLongLabel(context.getString(R.string.shortcut_post_long_label))
            .setDisabledMessage(context.getString(R.string.shortcut_post_disabled))
            .setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_post))
            .setIntent(intent)
            .build();
    shortcutManager.addDynamicShortcuts(Collections.singletonList(postShortcut));
}
项目:AwakeDebug    文件:ShortcutUtils.java   
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
@NonNull
private static ShortcutInfo createShortcut(Context context,
                                           String extraName,
                                           boolean enabled,
                                           String shortcutId,
                                           String shortLabel,
                                           String longLabel,
                                           int rank) {

    Intent intent = new Intent(context, AppShortcutActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_RUN);
    intent.putExtra(extraName, enabled);

    Icon acIcon = Icon.createWithResource(context, enabled ? R.drawable.ic_check_box : R.drawable.ic_check_box_blank);
    return new ShortcutInfo.Builder(context.getApplicationContext(), shortcutId)
            .setShortLabel(shortLabel)
            .setLongLabel(longLabel)
            .setIcon(acIcon)
            .setRank(rank)
            .setIntent(intent)
            .build();
}
项目:SecondScreen    文件:MainActivity.java   
private void setLauncherShortcuts() {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

        if(shortcutManager.getDynamicShortcuts().size() == 0) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClassName(BuildConfig.APPLICATION_ID, TaskerQuickActionsActivity.class.getName());
            intent.putExtra("launched-from-app", true);

            ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "quick_actions")
                    .setShortLabel(getString(R.string.label_quick_actions))
                    .setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon))
                    .setIntent(intent)
                    .build();

            shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
        }
    }
}
项目:justintrain-client-android    文件:ShortcutHelper.java   
private static List<ShortcutInfo> setShortcuts(Context context, PreferredJourney j) {
    Intent i1 = buildIntent(context, j);
    Intent i2 = buildIntent(context, j.swapStations());
    j.swapStations();

    ShortcutInfo       shortcut1 = buildShortcut(context, i1, j.getStation1().getNameShort(), j.getStation2().getNameShort(), "shortcut_dynamic1");
    ShortcutInfo       shortcut2 = buildShortcut(context, i2, j.getStation2().getNameShort(), j.getStation1().getNameShort(), "shortcut_dynamic2");
    List<ShortcutInfo> l         = new LinkedList<>();
    l.add(shortcut2);
    l.add(shortcut1);
    return l;
}
项目:justintrain-client-android    文件:ShortcutHelper.java   
private static ShortcutInfo buildShortcut(Context context, Intent i, String name1, String name2, String id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        return new ShortcutInfo.Builder(context, id)
                .setShortLabel(shortenStationName(name1) + " > " + shortenStationName(name2))
                .setLongLabel(name1 + " > " + name2)
                .setIcon(Icon.createWithResource(context, R.drawable.ic_arrow_forward))
                .setIntents(new Intent[]{
                        new Intent(Intent.ACTION_MAIN, Uri.EMPTY, context, FavouriteJourneysActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK),
                        i,
                })
                .build();
    } else {
        return null;
    }
}
项目:LaunchEnr    文件:LauncherAppsCompatVL.java   
public void onShortcutsChanged(@NonNull String packageName, @NonNull List<ShortcutInfo> shortcuts,
                               @NonNull UserHandle user) {
    List<ShortcutInfoCompat> shortcutInfoCompats = new ArrayList<>(shortcuts.size());
    for (ShortcutInfo shortcutInfo : shortcuts) {
        shortcutInfoCompats.add(new ShortcutInfoCompat(shortcutInfo));
    }

    mCallback.onShortcutsChanged(packageName, shortcutInfoCompats, user);
}
项目:LaunchEnr    文件:DeepShortcutManager.java   
/**
 * Query the system server for all the shortcuts matching the given parameters.
 * If packageName == null, we query for all shortcuts with the passed flags, regardless of app.
 *
 * TODO: Use the cache to optimize this so we don't make an RPC every time.
 */
@TargetApi(25)
private List<ShortcutInfoCompat> query(int flags, String packageName,
        ComponentName activity, List<String> shortcutIds, UserHandle user) {
    if (AndroidVersion.isAtLeastNougatMR1) {
        ShortcutQuery q = new ShortcutQuery();
        q.setQueryFlags(flags);
        if (packageName != null) {
            q.setPackage(packageName);
            q.setActivity(activity);
            q.setShortcutIds(shortcutIds);
        }
        List<ShortcutInfo> shortcutInfos = null;
        try {
            shortcutInfos = mLauncherApps.getShortcuts(q, user);
            mWasLastCallSuccess = true;
        } catch (SecurityException|IllegalStateException e) {
            e.printStackTrace();
            mWasLastCallSuccess = false;
        }
        if (shortcutInfos == null) {
            return Collections.EMPTY_LIST;
        }
        List<ShortcutInfoCompat> shortcutInfoCompats = new ArrayList<>(shortcutInfos.size());
        for (ShortcutInfo shortcutInfo : shortcutInfos) {
            shortcutInfoCompats.add(new ShortcutInfoCompat(shortcutInfo));
        }
        return shortcutInfoCompats;
    } else {
        return Collections.EMPTY_LIST;
    }
}
项目:LaunchEnr    文件:PinShortcutRequestActivityInfo.java   
@Override
public com.enrico.launcher3.ShortcutInfo createShortcutInfo() {
    // Total duration for the drop animation to complete.
    long duration = mContext.getResources().getInteger(R.integer.config_dropAnimMaxDuration) +
            Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT +
            mContext.getResources().getInteger(R.integer.config_overlayTransitionTime) / 2;
    // Delay the actual accept() call until the drop animation is complete.
    return LauncherAppsCompat.createShortcutInfoFromPinItemRequest(
            mContext, mRequest, duration);
}
项目:Espresso    文件:OnboardingActivity.java   
private void enableShortcuts() {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        ShortcutManager manager =  getSystemService(ShortcutManager.class);
        ShortcutInfo addPkg = new ShortcutInfo.Builder(this, "shortcut_add_package")
                .setLongLabel(getString(R.string.shortcut_label_add_package))
                .setShortLabel(getString(R.string.shortcut_label_add_package))
                .setIcon(Icon.createWithResource(this, R.drawable.ic_shortcut_add))
                .setIntent(
                        new Intent(OnboardingActivity.this, AddPackageActivity.class)
                                .setAction(Intent.ACTION_VIEW)
                                .addCategory(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION)
                )
                .build();
        ShortcutInfo scanCode = new ShortcutInfo.Builder(this, "shortcut_scan_code")
                .setIcon(Icon.createWithResource(this, R.drawable.ic_shortcut_filter_center_focus))
                .setLongLabel(getString(R.string.shortcut_label_scan_code))
                .setShortLabel(getString(R.string.shortcut_label_scan_code))
                .setIntent(
                        new Intent(OnboardingActivity.this, AddPackageActivity.class)
                                .setAction("io.github.marktony.espresso.mvp.addpackage.AddPackageActivity")
                                .addCategory(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION)
                )
                .build();
        ShortcutInfo search = new ShortcutInfo.Builder(this, "shortcut_search")
                .setIcon(Icon.createWithResource(this, R.drawable.ic_shortcut_search))
                .setLongLabel(getString(R.string.shortcut_label_search))
                .setShortLabel(getString(R.string.shortcut_label_search))
                .setIntent(
                        new Intent(OnboardingActivity.this, SearchActivity.class)
                                .setAction(Intent.ACTION_VIEW)
                                .addCategory(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION)
                )
                .build();
        manager.setDynamicShortcuts(Arrays.asList(addPkg, scanCode, search));
    }

}
项目:hypertrack-live-android    文件:Home.java   
private void addDynamicShortcut(Place place) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
            ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
            String name = HTTextUtils.isEmpty(place.getName()) ? place.getAddress() : place.getName();
            int count = 0;
            if (shortcutManager.getDynamicShortcuts() != null) {
                count = shortcutManager.getDynamicShortcuts().size();
            }
            if (count > 2) {
                String id = shortcutManager.getDynamicShortcuts().get(0).getId();
                List<String> shortcutIds = new ArrayList<>();
                shortcutIds.add(id);
                shortcutManager.removeDynamicShortcuts(shortcutIds);
            }

            List<ShortcutInfo> shortcut = new ArrayList<>();

            shortcut.add(0, new ShortcutInfo.Builder(this, place.getLocation().getLatLng().toString())
                    .setShortLabel(name)
                    .setIcon(Icon.createWithResource(this, R.drawable.ic_marker_gray))
                    .setIntent(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("share.location://hypertrack")))
                    .build());
            shortcutManager.addDynamicShortcuts(shortcut);
        }
    } catch (Exception e) {
        Crashlytics.logException(e);
    }
}
项目:Loyalty    文件:LauncherInfoManager.java   
@TargetApi(26)
private void createPinnedShortcut(Card card, Icon icon) {
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);

    if (shortcutManager.isRequestPinShortcutSupported()) {
        ShortcutInfo pin = new ShortcutInfo.Builder(context, card.getName() + "_pin")
                .setShortLabel(card.getName())
                .setIntent(createCardShortcutIntent(card))
                .setIcon(icon)
                .build();
        shortcutManager.requestPinShortcut(pin, null);
    }
}