Skip to content

Commit

Permalink
v 1.1.13 fix xiaomi
Browse files Browse the repository at this point in the history
  • Loading branch information
leolin310148 committed Feb 4, 2017
1 parent a56ebde commit bcb3afd
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.

Copy link
@mopsalarm

mopsalarm Feb 9, 2017

This actually shows an empty notification for xiaomi users of my app! :/

This comment has been minimized.

Copy link
@jkasten2

jkasten2 Feb 28, 2017

@mopsalarm Seeing the same. Going to add more details on my finding to the open issue #170.

.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);
}
}

Expand Down

0 comments on commit bcb3afd

Please sign in to comment.