【问题标题】:I want to show unread notification count on my app icon like whatsapp我想在我的应用程序图标上显示未读通知计数,例如 whatsapp
【发布时间】:2017-05-05 08:15:16
【问题描述】:

我已经使用 volley 库在我的应用程序中创建了通知,它调用 firebase 服务器我的问题是当我在特定用户(设备)中推送通知时,更新通知仅显示并且未读通知计数未显示,所以我想未读通知计数如何显示在我的应用程序图标中。帮帮我..

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

【问题讨论】:

  • 我觉得这个功能需要ROM支持。 AOSP 不支持图标角落的数字。
  • 如何..?Rom和AOSP是什么意思..?
  • 我认为您要查找的术语“未读通知计数”是徽章计数。
  • @Anbu AOSP 意味着 sdk 类似的东西,我同意 AL 的观点。很多厂商可能会实现这个功能,但我认为他们不会给你这个优先级来改变这个,如果你有这个权限,主屏幕会有多大。

标签: android firebase push-notification android-volley android-notifications


【解决方案1】:

如果您需要在主屏幕上的应用程序图标上显示通知计数,默认情况下该功能本身不包含在 Android SDK 中,但每个制造商可能会或可能不会让您访问其自定义 api 以允许该制造商制作此类功能例如以下代码适用于 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);

索尼启动器上的以下工作

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

您可以看到每个启动器的代码都不同,这有点蹩脚,会让您头疼 幸运的是,有人将大多数著名的发射器收集在一个库中ShortcutBadger
其中,您可以在他们的 github 上找到他们支持的启动器

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-24
    • 1970-01-01
    • 2016-09-19
    • 2016-04-10
    • 2014-04-16
    • 1970-01-01
    • 2015-12-01
    • 1970-01-01
    相关资源
    最近更新 更多