本文整理汇总了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();
}
}
示例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);
}
示例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));
}
示例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));
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}