Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure isBadgeCounterSupported returns false on Samsung on Android 8+ #268

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ public void onClick(View view) {
}
});

Button isBadgeSupportedBtn = (Button) findViewById(R.id.btnIsBadgeSupported);
isBadgeSupportedBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean success = ShortcutBadger.isBadgeCounterSupported(MainActivity.this);

Toast.makeText(getApplicationContext(), "isBadgeCounterSupported=" + success, Toast.LENGTH_SHORT).show();
}
});


//find the home launcher Package
Intent intent = new Intent(Intent.ACTION_MAIN);
Expand Down
8 changes: 8 additions & 0 deletions SampleApp/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,13 @@
android:layout_centerVertical="true"
android:text="Remove badge"/>

<Button
android:id="@+id/btnIsBadgeSupported"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Is badge supported?"/>


</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -23,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"
);
}
}
}