首页 > 解决方案 > android fcm主题订阅者停止接收通知

问题描述

突然,android 设备停止从服务器接收有关已订阅其工作几天的主题的通知,然后在每次安装后停止,但是当从控制台发送到相同的主题时,它已交付。

我的清单

<meta-data
    android:name="com.google.firebase.messaging.default_notification_channel_id"
    android:value="com.myapp.channelId" />



<service
    android:name=".firebase.MyFirebaseMessagingService"
    android:enabled="true"
    android:exported="false">
  <intent-filter>
    <action android:name="com.google.firebase.MESSAGING_EVENT" />
  </intent-filter>
</service>

渠道

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    NotificationChannel androidChannel = null;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {

        androidChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
                NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);

        AudioAttributes audioAttributes =new AudioAttributes.Builder()
                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                .build();


        androidChannel.setSound(Uri.parse("android.resources://" + getPackageName() + "/" + R.raw.silence),audioAttributes);

        androidChannel.enableLights(true);
        androidChannel.setLightColor(Color.RED);
        androidChannel.enableVibration(true);
        mNotificationManager.createNotificationChannel(androidChannel);
    }

我们的 bakend 使用传统的 http Legacy HTTP:https ://fcm.googleapis.com/fcm/send

有了这个 json

{
    "condition":  "'A' in topics && 'B' in topics" ,
    "time_to_live": 3600,
   "priority": "high",
    "android":  {
        "priority":  "high"
    },
   "notification":  {
         "body" :  "body",
       "title" :  "title"
    },
   "data":  {
       "id" :  "123
    }
}";

我们通过从控制台发送主题来确保用户仍然订阅主题,并且它运行良好。

标签: androidpush-notificationfirebase-cloud-messaging

解决方案


推荐阅读