當前位置: 首頁>>代碼示例>>Java>>正文


Java ShortcutInfo類代碼示例

本文整理匯總了Java中android.content.pm.ShortcutInfo的典型用法代碼示例。如果您正苦於以下問題:Java ShortcutInfo類的具體用法?Java ShortcutInfo怎麽用?Java ShortcutInfo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ShortcutInfo類屬於android.content.pm包,在下文中一共展示了ShortcutInfo類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: pinShortcutToHomeScreen

import android.content.pm.ShortcutInfo; //導入依賴的package包/類
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();
    }
}
 
開發者ID:akexorcist,項目名稱:Android-O-Feature,代碼行數:12,代碼來源:PinningActivity.java

示例2: updateDynamicShortcuts

import android.content.pm.ShortcutInfo; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:AbyxBelgium,項目名稱:Loyalty,代碼行數:32,代碼來源:LauncherInfoManager.java

示例3: createShortcut

import android.content.pm.ShortcutInfo; //導入依賴的package包/類
@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));
}
 
開發者ID:frowhy,項目名稱:Wake,代碼行數:24,代碼來源:WakeActivity.java

示例4: createShortcut

import android.content.pm.ShortcutInfo; //導入依賴的package包/類
@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));
    }
}
 
開發者ID:Omico,項目名稱:CurrentActivity,代碼行數:20,代碼來源:SplashActivity.java

示例5: createShortcutList

import android.content.pm.ShortcutInfo; //導入依賴的package包/類
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;
}
 
開發者ID:marcoscgdev,項目名稱:shortcut-helper,代碼行數:20,代碼來源:ShortcutHelper.java

示例6: createShortcuts

import android.content.pm.ShortcutInfo; //導入依賴的package包/類
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;
}
 
開發者ID:MatthiasRobbers,項目名稱:shortbread,代碼行數:18,代碼來源:ShortbreadGenerated.java

示例7: createShortcuts

import android.content.pm.ShortcutInfo; //導入依賴的package包/類
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);
}
 
開發者ID:MatthiasRobbers,項目名稱:shortbread,代碼行數:18,代碼來源:ResourcesShortcutActivityGenerated.java

示例8: createShortcuts

import android.content.pm.ShortcutInfo; //導入依賴的package包/類
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);
}
 
開發者ID:MatthiasRobbers,項目名稱:shortbread,代碼行數:17,代碼來源:BackStackShortcutActivityGenerated.java

示例9: createShortcuts

import android.content.pm.ShortcutInfo; //導入依賴的package包/類
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);
}
 
開發者ID:MatthiasRobbers,項目名稱:shortbread,代碼行數:27,代碼來源:TwoShortcutActivitiesGenerated.java

示例10: createShortcuts

import android.content.pm.ShortcutInfo; //導入依賴的package包/類
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);
}
 
開發者ID:MatthiasRobbers,項目名稱:shortbread,代碼行數:18,代碼來源:AdvancedShortcutActivityGenerated.java

示例11: createShortcuts

import android.content.pm.ShortcutInfo; //導入依賴的package包/類
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);
}
 
開發者ID:MatthiasRobbers,項目名稱:shortbread,代碼行數:26,代碼來源:TwoMethodShortcutActivitiesGenerated.java

示例12: createShortcuts

import android.content.pm.ShortcutInfo; //導入依賴的package包/類
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);
}
 
開發者ID:MatthiasRobbers,項目名稱:shortbread,代碼行數:26,代碼來源:TwoMethodShortcutsActivityGenerated.java

示例13: addChoiceShortcuts

import android.content.pm.ShortcutInfo; //導入依賴的package包/類
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);
}
 
開發者ID:nicholasrout,項目名稱:shortstories,代碼行數:26,代碼來源:ChoiceActivity.java

示例14: getNextRailNumber

import android.content.pm.ShortcutInfo; //導入依賴的package包/類
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;
}
 
開發者ID:nirhart,項目名稱:shortrain,代碼行數:20,代碼來源:ShortcutsUtils.java

示例15: addAppShortcut

import android.content.pm.ShortcutInfo; //導入依賴的package包/類
/**
 * 添加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);
    }
}
 
開發者ID:XYScience,項目名稱:StopApp,代碼行數:28,代碼來源:ShortcutsManager.java


注:本文中的android.content.pm.ShortcutInfo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。