@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));
}
WakeActivity.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:Wake
作者:
评论列表
文章目录