Reputation: 17
I have created notification in my app using volley library it's calling to firebase server my problem is when i push the notification in specific user(device) the update notification only showing and unread notification count number is not showing, so i want to unread notification count number how to display in my app icon. help me ..
My code is:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG="MyMessageservice";
RemoteMessage remoteMessage;
@Override
public void onMessageReceived(RemoteMessage remoteMessage){
String title=remoteMessage.getNotification().getTitle();
String message=remoteMessage.getNotification().getBody();
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// String click_action=remoteMessage.getNotification().getClickAction();
Intent intent=new Intent(this,VisitorList.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri notificattionSound= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationbuilder = new NotificationCompat.Builder(this);
notificationbuilder.setContentTitle(title);
notificationbuilder.setContentText(message);
notificationbuilder.setAutoCancel(true);
notificationbuilder.setSound(notificattionSound);
notificationbuilder.setSmallIcon(R.drawable.ic_launcher);
notificationbuilder.setContentIntent(pendingIntent);
notificationbuilder.setAutoCancel(true);
notificationManager.notify(0, notificationbuilder.build());
}
}
Upvotes: 2
Views: 4688
Reputation: 343
If you need to show notification count on app icon on your home screen, the function itself is not included in Android SDK by default, but every manufacture may or may not give you access to its custom api that allow that manufacture to make such functionality for example the following code work on samsung Touchwiz
Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
intent.putExtra("badge_count", count);
intent.putExtra("badge_count_package_name", "your package name");
sendBroadcast(intent);
the following work on sony launcher
Intent intent = new Intent("com.sonyericsson.home.action.UPDATE_BADGE");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", count);
intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", "your package name");
sendBroadcast(intent);
as you can see it's different code for every launcher which is kinda lame and would give you a headache
Fortunately, someone gathers most of famous launchers in one library ShortcutBadger
Which, as you can find on their github the launchers they support
Upvotes: 1