长按快捷方式
@TargetApi(Build.VERSION_CODES.N_MR1)private ShortcutInfo createShortcutInfo1() {return new ShortcutInfo.Builder(this, "99009").setShortLabel("909888").setLongLabel("909888").setIcon(Icon.createWithResource(this, R.drawable.ic_launcher)).setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://xiaweizi.cn/"))).build();}private void setDynamicShortcuts() {if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);List<ShortcutInfo> shortcutInfo = new ArrayList<>();shortcutInfo.add(createShortcutInfo1());
// shortcutInfo.add(createShortcutInfo2());if (shortcutManager != null) {shortcutManager.setDynamicShortcuts(shortcutInfo);}}}
桌面快捷图标
private void createPinnedShortcuts() {if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);if (shortcutManager != null && shortcutManager.isRequestPinShortcutSupported()) {Intent intent = new Intent(this, TestActivity.class);intent.setAction(Intent.ACTION_VIEW);intent.putExtra("key", "fromPinnedShortcut");ShortcutInfo pinShortcutInfo = new ShortcutInfo.Builder(this, "my-shortcut").setShortLabel(("0000")).setLongLabel(("0000")).setIcon(Icon.createWithResource(this, R.drawable.ic_launcher)).setIntent(intent).build();Intent pinnedShortcutCallbackIntent = shortcutManager.createShortcutResultIntent(pinShortcutInfo);PendingIntent successCallback = PendingIntent.getBroadcast(this, 0,pinnedShortcutCallbackIntent, FLAG_IMMUTABLE);boolean b = shortcutManager.requestPinShortcut(pinShortcutInfo, successCallback.getIntentSender());showToast("set pinned shortcuts " + (b ? "success" : "failed") + "!");}}}
https://cloud.tencent.com/developer/article/1444202