android.content.pm.ShortcutManager#removeDynamicShortcuts()源码实例Demo

下面列出了android.content.pm.ShortcutManager#removeDynamicShortcuts() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: rcloneExplorer   文件: AppShortcutsHelper.java
public static void removeAppShortcut(Context context, String remoteName) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) {
        return;
    }

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    Set<String> appShortcutIds = sharedPreferences.getStringSet(context.getString(R.string.shared_preferences_app_shortcuts), new HashSet<String>());
    String id = getUniqueIdFromString(remoteName);

    if (!appShortcutIds.contains(id)) {
        return;
    }

    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    if (shortcutManager == null) {
        return;
    }

    List<ShortcutInfo> shortcutInfoList = shortcutManager.getDynamicShortcuts();
    for (ShortcutInfo shortcutInfo : shortcutInfoList) {
        if (shortcutInfo.getId().equals(id)) {
            shortcutManager.removeDynamicShortcuts(Collections.singletonList(shortcutInfo.getId()));
            return;
        }
    }

    SharedPreferences.Editor editor = sharedPreferences.edit();
    appShortcutIds.remove(id);
    Set<String> updateAppShortcutIds = new HashSet<>(appShortcutIds);
    editor.putStringSet(context.getString(R.string.shared_preferences_app_shortcuts), updateAppShortcutIds);
    editor.apply();
}
 
源代码2 项目: rcloneExplorer   文件: AppShortcutsHelper.java
public static void removeAppShortcutIds(Context context, List<String> ids) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) {
        return;
    }

    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    if (shortcutManager == null) {
        return;
    }

    shortcutManager.removeDynamicShortcuts(ids);
}
 
源代码3 项目: zapp   文件: ShortcutHelper.java
/**
 * Removes the given channel as shortcut from the launcher icon.
 * Only call on api level >= 25.
 *
 * @param context   to access system services
 * @param channelId id of the channel you want to remove from shorcut menu
 */
@TargetApi(25)
public static void removeShortcutForChannel(Context context, String channelId) {
	ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
	if (shortcutManager != null) {
		shortcutManager.removeDynamicShortcuts(Collections.singletonList(channelId));
	}
}
 
源代码4 项目: 365browser   文件: LauncherShortcutActivity.java
/**
 * 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);
}
 
源代码5 项目: shortrain   文件: RailActionActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

    String id = getIntent().getExtras().getString(RAIL_ID_KEY);
    int railNumber = ShortcutsUtils.getRailNumber(id);

    int rotation = getIntent().getExtras().getInt(RAIL_ROTATION_KEY);

    int nextIcon = 0;
    int nextRotation = 0;

    switch (rotation) {
        case RailInfo.NOT_SET:
            nextIcon = R.drawable.horizontal;
            nextRotation = RailInfo.HORIZONTAL;
            break;
        case RailInfo.HORIZONTAL:
            nextIcon = R.drawable.vertical;
            nextRotation = RailInfo.VERTICAL;
            break;
        case RailInfo.VERTICAL:
            nextIcon = R.drawable.bottom_left_corner;
            nextRotation = RailInfo.BOTTOM_LEFT_CORNER;
            break;
        case RailInfo.BOTTOM_LEFT_CORNER:
            nextIcon = R.drawable.bottom_right_corner;
            nextRotation = RailInfo.BOTTOM_RIGHT_CORNER;
            break;
        case RailInfo.BOTTOM_RIGHT_CORNER:
            nextIcon = R.drawable.top_left_corner;
            nextRotation = RailInfo.TOP_LEFT_CORNER;
            break;
        case RailInfo.TOP_LEFT_CORNER:
            nextIcon = R.drawable.top_right_corner;
            nextRotation = RailInfo.TOP_RIGHT_CORNER;
            break;
        case RailInfo.TOP_RIGHT_CORNER:
            nextIcon = R.drawable.horizontal;
            nextRotation = RailInfo.HORIZONTAL;
            break;
    }

    Rect r = getIntent().getSourceBounds();
    ShortcutInfo thisRailShortcut = ShortcutsUtils.createRailShortcut(this, railNumber, nextIcon, nextRotation, r);

    shortcutManager.updateShortcuts(Collections.singletonList(thisRailShortcut));
    shortcutManager.removeDynamicShortcuts(Collections.singletonList(id));

    int newRailId = ShortcutsUtils.getNextRailNumber(shortcutManager);
    ShortcutInfo railShortcut = ShortcutsUtils.createRailShortcut(this, newRailId);
    shortcutManager.addDynamicShortcuts(Collections.singletonList(railShortcut));
    finish();

    super.onCreate(savedInstanceState);
}
 
public static void removeShortcut(Activity activity, SoundProfile soundProfile) {
    ShortcutManager shortcutManager = activity.getSystemService(ShortcutManager.class);
    shortcutManager.removeDynamicShortcuts(Collections.singletonList(profileToShortcutId(soundProfile)));
}