【问题标题】:Can I send firebase notification in a specific android version?我可以在特定的 android 版本中发送 firebase 通知吗?
【发布时间】:2022-10-25 16:38:44
【问题描述】:

我的应用程序以某种方式仅在 android 12 上崩溃。所以我只想向 android 12 用户发送通知。 firebase FCM可以吗?

【问题讨论】:

    标签: android firebase firebase-cloud-messaging


    【解决方案1】:

    检查设备是否为android 12,如果是,则订阅一个主题

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S || "S".equals(Build.VERSION.CODENAME)) {  //Check if it is android 12
       FirebaseMessaging.getInstance().subscribeToTopic("android12")  //subscribe to topic ( Ex : android12 )
        .addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                if (task.isSuccessful()) {
                    //subscribed
                }
            }
        });
    }
    

    https://firebase.google.com/docs/cloud-messaging/android/send-multiple

    然后向主题(Android 12 设备已订阅的主题)发送 fcm 通知

    {
     "message":{
     "topic":"android12",
     "notification":{
       "body" : "",  //add body of notification
       "title" : "", //add title of notification
      }
     }
    }
    

    https://firebase.google.com/docs/cloud-messaging/send-message

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-30
      • 1970-01-01
      • 2021-11-05
      • 1970-01-01
      • 1970-01-01
      • 2018-07-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多