Java Code Examples for android.content.pm.ShortcutManager#removeDynamicShortcuts()

The following examples show how to use android.content.pm.ShortcutManager#removeDynamicShortcuts() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppShortcutsHelper.java    From rcloneExplorer with MIT License 5 votes vote down vote up
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();
}
 
Example 2
Source File: AppShortcutsHelper.java    From rcloneExplorer with MIT License 5 votes vote down vote up
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);
}
 
Example 3
Source File: ShortcutHelper.java    From zapp with MIT License 5 votes vote down vote up
/**
 * 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));
	}
}
 
Example 4
Source File: LauncherShortcutActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source File: RailActionActivity.java    From shortrain with MIT License 4 votes vote down vote up
@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);
}
 
Example 6
Source File: DynamicShortcutManager.java    From volume_control_android with MIT License 4 votes vote down vote up
public static void removeShortcut(Activity activity, SoundProfile soundProfile) {
    ShortcutManager shortcutManager = activity.getSystemService(ShortcutManager.class);
    shortcutManager.removeDynamicShortcuts(Collections.singletonList(profileToShortcutId(soundProfile)));
}