下面列出了android.content.pm.ShortcutManager#disableShortcuts() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Removes the dynamic "New incognito tab" launcher shortcut.
* @param context The context used to retrieve the system {@link ShortcutManager}.
*/
@TargetApi(Build.VERSION_CODES.N_MR1)
private static void removeIncognitoLauncherShortcut(Context context) {
List<String> shortcutList = new ArrayList<>();
shortcutList.add(DYNAMIC_OPEN_NEW_INCOGNITO_TAB_ID);
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
shortcutManager.disableShortcuts(shortcutList);
shortcutManager.removeDynamicShortcuts(shortcutList);
}
private void updateDynamicShortcuts() {
ShortcutManager shortcutManager;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
Intent intentGenerateQrCode = new Intent(this, MainActivity.class);
intentGenerateQrCode.setFlags((Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));
intentGenerateQrCode.setAction(Constants.ACTION_GENERATE_QR_CODE);
ShortcutInfo shortcutGenerateQrCode = new ShortcutInfo.Builder(this, SHORTCUT_ID_GENERATE_QR_CODE)
.setShortLabel(getString(R.string.shortcut_generate_qr_code))
.setLongLabel(getString(R.string.shortcut_generate_qr_code))
.setIcon(Icon.createWithResource(this, R.drawable.ic_shortcut_qr))
.setIntent(intentGenerateQrCode)
.build();
Intent intentTransferIotas = new Intent(this, MainActivity.class);
intentTransferIotas.setFlags((Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));
intentTransferIotas.setAction(Constants.ACTION_SEND_TRANSFER);
ShortcutInfo shortcutTransferIotas = new ShortcutInfo.Builder(this, SHORTCUT_ID_SEND_TRANSFER)
.setShortLabel(getString(R.string.shortcut_send_transfer))
.setLongLabel(getString(R.string.shortcut_send_transfer))
.setIcon(Icon.createWithResource(this, R.drawable.ic_shortcut_transaction))
.setIntent(intentTransferIotas)
.build();
shortcutManager = getSystemService(ShortcutManager.class);
if (shortcutManager != null) {
if (IOTA.seed != null) {
shortcutManager.setDynamicShortcuts(Arrays.asList(shortcutGenerateQrCode, shortcutTransferIotas));
shortcutManager.enableShortcuts(Arrays.asList(SHORTCUT_ID_GENERATE_QR_CODE, SHORTCUT_ID_SEND_TRANSFER));
} else {
// remove shortcuts if Iota.seed.isEmpty()
shortcutManager.disableShortcuts(Arrays.asList(SHORTCUT_ID_GENERATE_QR_CODE, SHORTCUT_ID_SEND_TRANSFER));
shortcutManager.removeAllDynamicShortcuts();
}
}
}
}
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void disablePostShortcut(@NonNull Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
shortcutManager.disableShortcuts(DYNAMIC_SHORTCUT_IDS);
}