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