Skip to content

Commit

Permalink
Make sure isBadgeCounterSupported returns false on Samsung on Android 8+
Browse files Browse the repository at this point in the history
Note that the DefaultBadger also must check for Samsung on Android 8, or
it will be used on those devices.

This fixes leolin310148#266
  • Loading branch information
eirikwah committed Feb 28, 2018
1 parent c072deb commit 6515111
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

import java.util.Arrays;
import java.util.List;
Expand All @@ -22,6 +23,12 @@ public class DefaultBadger implements Badger {

@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {
// The broadcast of "android.intent.action.BADGE_COUNT_UPDATE" is successfull on Samsung
// devices running Android 8, but it has no effect on badges. So we must check explicitly:
if (Build.MANUFACTURER.equalsIgnoreCase("Samsung") && Build.VERSION.SDK_INT >= 26) {
throw new ShortcutBadgeException("ShortcutBadger is not supported on Samsung devices running Android 8 (or newer)");
}

Intent intent = new Intent(INTENT_ACTION);
intent.putExtra(INTENT_EXTRA_BADGE_COUNT, badgeCount);
intent.putExtra(INTENT_EXTRA_PACKAGENAME, componentName.getPackageName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.os.Build;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import me.leolin.shortcutbadger.Badger;
Expand All @@ -25,7 +26,8 @@ public class SamsungHomeBadger implements Badger {
private DefaultBadger defaultBadger;

public SamsungHomeBadger() {
if (Build.VERSION.SDK_INT >= 21) {
// Use default badger on Android 5.0 to Android 7.1, but not on Android 8 and newer:
if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 26) {
defaultBadger = new DefaultBadger();
}
}
Expand Down Expand Up @@ -77,9 +79,14 @@ private ContentValues getContentValues(ComponentName componentName, int badgeCou

@Override
public List<String> getSupportLaunchers() {
return Arrays.asList(
"com.sec.android.app.launcher",
"com.sec.android.app.twlauncher"
);
if (Build.VERSION.SDK_INT >= 26) {
// Not supported on Android 8 (and newer)
return Collections.emptyList();
} else {
return Arrays.asList(
"com.sec.android.app.launcher",
"com.sec.android.app.twlauncher"
);
}
}
}

0 comments on commit 6515111

Please sign in to comment.