-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a56ebde
commit bcb3afd
Showing
1 changed file
with
9 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,16 +49,15 @@ public void executeBadge(Context context, ComponentName componentName, int badge | |
localIntent.putExtra(EXTRA_UPDATE_APP_MSG_TEXT, String.valueOf(badgeCount == 0 ? "" : badgeCount)); | ||
if (BroadcastHelper.canResolveBroadcast(context, localIntent)) { | ||
context.sendBroadcast(localIntent); | ||
} else { | ||
if (Build.MANUFACTURER.equalsIgnoreCase("Xiaomi")) { | ||
tryNewMiuiBadge(context, badgeCount); | ||
} | ||
} | ||
} | ||
if (Build.MANUFACTURER.equalsIgnoreCase("Xiaomi")) { | ||
tryNewMiuiBadge(context, badgeCount); | ||
} | ||
} | ||
|
||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) | ||
private void tryNewMiuiBadge(Context context, int badgeCount) { | ||
private void tryNewMiuiBadge(Context context, int badgeCount) throws ShortcutBadgeException { | ||
if (resolveInfo == null) { | ||
Intent intent = new Intent(Intent.ACTION_MAIN); | ||
intent.addCategory(Intent.CATEGORY_HOME); | ||
|
@@ -69,17 +68,19 @@ private void tryNewMiuiBadge(Context context, int badgeCount) { | |
NotificationManager mNotificationManager = (NotificationManager) context | ||
.getSystemService(Context.NOTIFICATION_SERVICE); | ||
Notification.Builder builder = new Notification.Builder(context) | ||
.setContentTitle(context.getString(resolveInfo.labelRes)).setContentText(context.getString(resolveInfo.labelRes)).setSmallIcon(resolveInfo.getIconResource()); | ||
.setContentTitle("") | ||
.setContentText("") | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jkasten2
|
||
.setSmallIcon(resolveInfo.getIconResource()); | ||
Notification notification = builder.build(); | ||
try { | ||
Field field = notification.getClass().getDeclaredField("extraNotification"); | ||
Object extraNotification = field.get(notification); | ||
Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class); | ||
method.invoke(extraNotification, badgeCount); | ||
mNotificationManager.notify(0, notification); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
throw new ShortcutBadgeException("not able to set badge", e); | ||
} | ||
mNotificationManager.notify(0, notification); | ||
} | ||
} | ||
|
||
|
This actually shows an empty notification for xiaomi users of my app! :/