当前位置: 首页>>代码示例>>Java>>正文


Java ShortcutManager类代码示例

本文整理汇总了Java中android.content.pm.ShortcutManager的典型用法代码示例。如果您正苦于以下问题:Java ShortcutManager类的具体用法?Java ShortcutManager怎么用?Java ShortcutManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ShortcutManager类属于android.content.pm包,在下文中一共展示了ShortcutManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pinShortcutToHomeScreen

import android.content.pm.ShortcutManager; //导入依赖的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.ShortcutManager; //导入依赖的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.ShortcutManager; //导入依赖的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.ShortcutManager; //导入依赖的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.ShortcutManager; //导入依赖的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: addChoiceShortcuts

import android.content.pm.ShortcutManager; //导入依赖的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

示例7: getNextRailNumber

import android.content.pm.ShortcutManager; //导入依赖的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

示例8: getRails

import android.content.pm.ShortcutManager; //导入依赖的package包/类
public static List<RailInfo> getRails(ShortcutManager shortcutManager) {
    List<ShortcutInfo> shortcuts = shortcutManager.getPinnedShortcuts();

    List<RailInfo> rails = new ArrayList<>();
    for (ShortcutInfo shortcutInfo : shortcuts) {
        String id = shortcutInfo.getId();
        if (isRailShortcut(id)) {
            PersistableBundle extras = shortcutInfo.getExtras();
            if (extras != null) {
                int[] posArray = extras.getIntArray(RailActionActivity.RAIL_RECT_KEY);
                int rotation = extras.getInt(RailActionActivity.RAIL_ROTATION_KEY);
                assert posArray != null;
                rails.add(new RailInfo(posArray[0], posArray[1], rotation));
            }
        }
    }

    return rails;
}
 
开发者ID:nirhart,项目名称:shortrain,代码行数:20,代码来源:ShortcutsUtils.java

示例9: handleIntent

import android.content.pm.ShortcutManager; //导入依赖的package包/类
/**
 * Handle the incoming intent of shortcut
 * Returns true if shortcut was handled, false otherwise
 */
private boolean handleIntent() {

    String shortcutID;

    if (getIntent().getAction() != null && getIntent().getAction().equals(SHORTCUT_INTENT_STRING)) {
        shortcutID = SHORTCUT_ID;
        doToggle();
    } else return false;

    /*
     * On Android 7.0 or below, bail out from now
     * This is because app shortcuts are not supported by default in those android versions
     * It however is supported in 3rd party launchers like nova launcher.
     * As android API guidelines suggest to reportShortcutUsed(), but that can be done only on API 25
     */
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return true;

    ShortcutManager shortcutManager = this.getSystemService(ShortcutManager.class);
    shortcutManager.reportShortcutUsed(shortcutID);

    return true;
}
 
开发者ID:corphish,项目名称:NightLight,代码行数:27,代码来源:StartActivity.java

示例10: create

import android.content.pm.ShortcutManager; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:27,代码来源:ShortcutsHandler.java

示例11: updateShortcut

import android.content.pm.ShortcutManager; //导入依赖的package包/类
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));
    }
}
 
开发者ID:iTXTech,项目名称:Daedalus,代码行数:26,代码来源:Daedalus.java

示例12: updateShortcuts

import android.content.pm.ShortcutManager; //导入依赖的package包/类
@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à. */
    }
}
 
开发者ID:FranckRJ,项目名称:RespawnIRC-Android,代码行数:25,代码来源:Utils.java

示例13: setupShortcuts

import android.content.pm.ShortcutManager; //导入依赖的package包/类
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);
    }
 
开发者ID:qibin0506,项目名称:Android7_Shortcuts_Demo,代码行数:22,代码来源:MainActivity.java

示例14: addShortcutForChannel

import android.content.pm.ShortcutManager; //导入依赖的package包/类
/**
 * 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;
	}
}
 
开发者ID:cemrich,项目名称:zapp,代码行数:31,代码来源:ShortcutHelper.java

示例15: updataShortcuts

import android.content.pm.ShortcutManager; //导入依赖的package包/类
@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);
}
 
开发者ID:8enet,项目名称:AppOpsX,代码行数:25,代码来源:Helper.java


注:本文中的android.content.pm.ShortcutManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。