Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 79eb61c

Browse files
authored
Merge pull request #646 from k2-digital/master
Updating ShortCutBadger for Android
2 parents 1ab980c + dd1bcbd commit 79eb61c

File tree

2 files changed

+2
-50
lines changed

2 files changed

+2
-50
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ dependencies {
4848
implementation "androidx.appcompat:appcompat:1.0.0"
4949
implementation 'com.facebook.react:react-native:+'
5050
implementation "com.google.android.gms:play-services-gcm:${safeExtGet('googlePlayServicesVersion', '+')}"
51-
implementation 'me.leolin:ShortcutBadger:1.1.8@aar'
51+
implementation 'me.leolin:ShortcutBadger:1.1.22@aar'
5252
implementation "com.google.firebase:firebase-messaging:${safeExtGet('firebaseMessagingVersion', '+')}"
5353
}

android/src/main/java/com/dieam/reactnativepushnotification/helpers/ApplicationBadgeHelper.java

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,18 @@
1010

1111
import me.leolin.shortcutbadger.Badger;
1212
import me.leolin.shortcutbadger.ShortcutBadger;
13-
import me.leolin.shortcutbadger.impl.SamsungHomeBadger;
1413

1514
/**
1615
* Helper for setting application launcher icon badge counts.
17-
* <p>
18-
* This is a wrapper around {@link ShortcutBadger}, with a couple enhancements:
19-
* <p>
20-
* - If the first attempt fails, don't retry. This keeps logs clean, as failed attempts are noisy.
21-
* - Test and apply a separate method for older Samsung devices, which ShortcutBadger has
22-
* (perhaps over-aggressively) deprecated. ref: https://github.com/leolin310148/ShortcutBadger/issues/40
16+
* This is a wrapper around {@link ShortcutBadger}:
2317
*/
2418
public class ApplicationBadgeHelper {
2519

2620
public static final ApplicationBadgeHelper INSTANCE = new ApplicationBadgeHelper();
2721

2822
private static final String LOG_TAG = "ApplicationBadgeHelper";
29-
private static final Badger LEGACY_SAMSUNG_BADGER = new SamsungHomeBadger();
3023

3124
private Boolean applyAutomaticBadger;
32-
private Boolean applySamsungBadger;
3325
private ComponentName componentName;
3426

3527
private ApplicationBadgeHelper() {
@@ -40,7 +32,6 @@ public void setApplicationIconBadgeNumber(Context context, int number) {
4032
componentName = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()).getComponent();
4133
}
4234
tryAutomaticBadge(context, number);
43-
tryLegacySamsungBadge(context, number);
4435
}
4536

4637
private void tryAutomaticBadge(Context context, int number) {
@@ -57,43 +48,4 @@ private void tryAutomaticBadge(Context context, int number) {
5748
}
5849
ShortcutBadger.applyCount(context, number);
5950
}
60-
61-
private void tryLegacySamsungBadge(Context context, int number) {
62-
// First attempt to apply legacy samsung badge. Check if eligible, then attempt it.
63-
if (null == applySamsungBadger) {
64-
applySamsungBadger = isLegacySamsungLauncher(context) && applyLegacySamsungBadge(context, number);
65-
if (applySamsungBadger) {
66-
FLog.i(LOG_TAG, "First attempt to use legacy Samsung badger succeeded; permanently enabling method.");
67-
} else {
68-
FLog.w(LOG_TAG, "First attempt to use legacy Samsung badger failed; permanently disabling method.");
69-
}
70-
return;
71-
} else if (!applySamsungBadger) {
72-
return;
73-
}
74-
applyLegacySamsungBadge(context, number);
75-
}
76-
77-
private boolean isLegacySamsungLauncher(Context context) {
78-
Intent intent = new Intent(Intent.ACTION_MAIN);
79-
intent.addCategory(Intent.CATEGORY_HOME);
80-
ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
81-
82-
if (resolveInfo == null || resolveInfo.activityInfo.name.toLowerCase().contains("resolver")) {
83-
return false;
84-
}
85-
86-
String currentHomePackage = resolveInfo.activityInfo.packageName;
87-
return LEGACY_SAMSUNG_BADGER.getSupportLaunchers().contains(currentHomePackage);
88-
}
89-
90-
private boolean applyLegacySamsungBadge(Context context, int number) {
91-
try {
92-
LEGACY_SAMSUNG_BADGER.executeBadge(context, componentName, number);
93-
return true;
94-
} catch (Exception e) {
95-
FLog.w(LOG_TAG, "Legacy Samsung badger failed", e);
96-
return false;
97-
}
98-
}
9951
}

0 commit comments

Comments
 (0)