Android Firebase推送通知标志不会更改其值

问题描述

我有一个有关Android Firebase的通知徽章的问题。我将通知推送到了我的设备(Android 7和Android 10)。在Android 7中,徽章增量看起来还可以。打开应用后,所有通知栏和徽章都会消失。

我将通知推送到我的Android 10,通知栏和徽章显示完美,但是通知徽章没有增加,并且卡在了某个数字上(在我的情况下是32)。我多次推送通知,结果仍然相同。

public class FCMService2 extends FirebaseMessagingService
{
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage)
    {
        String title = "";
        String message = "";

        if(remoteMessage.getNotification() != null)
        {
            title = remoteMessage.getNotification().getTitle();
            message = remoteMessage.getNotification().getBody();
        }

        if(remoteMessage.getData() != null)
        {
            if(remoteMessage.getData().get("title") != null && remoteMessage.getData().get("title").length() > 0)
            {
                title = remoteMessage.getData().get("title");
            }

            if(remoteMessage.getData().get("message") != null && remoteMessage.getData().get("message").length() > 0)
            {
                message = remoteMessage.getData().get("message");
            }
        }

        sendNotification(title,message);
    }

    private void sendNotification(String title,String message)
    {
        Random rand = new Random();
        int randomNum = rand.nextInt(999999);

        Intent intent = new Intent(this,LoginActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("title",title);
        intent.putExtra("message",message);

        PendingIntent pendingIntent = PendingIntent.getActivity(this,randomNum,intent,PendingIntent.FLAG_CANCEL_CURRENT);

        notificationmanager notificationmanager = (notificationmanager) getSystemService(Context.NOTIFICATION_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
        {
            NotificationChannel notificationChannel =  new NotificationChannel("mmc_cre_channel_id","mmc",notificationmanager.IMPORTANCE_DEFAULT);
            notificationChannel.enableLights(true);
            notificationChannel.enableVibration(true);
            notificationChannel.setShowBadge(true);
            notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
            notificationChannel.setVibrationPattern(new long[]{ 100,300,300});

            notificationmanager.createNotificationChannel(notificationChannel);
        }

        Uri defaultSoundUri = ringtoneManager.getDefaultUri(ringtoneManager.TYPE_NOTIFICATION);
        final  NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,"mmc_cre_channel_id")
                .setSmallIcon(R.mipmap.cre_logo)
                .setContentTitle(title)
                .setContentText(message)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setChannelId("mmc_cre_channel_id")
                .setContentIntent(pendingIntent);

        notificationmanager.notify(randomNum,notificationBuilder.build());
    }
}

这是我的Android Manifest.xml文件

   <Meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/profile_logo" />

    <Meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="mmc_cre_channel_id" />


    <service
        android:name=".utils.FCMToken"
        android:exported="false">
    </service>

    <service
        android:name=".utils.FCMService2"
        android:stopWithTask="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

</application>

有人可以帮我解决这个问题吗?谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)