【发布时间】:2022-10-25 16:38:44
【问题描述】:
我的应用程序以某种方式仅在 android 12 上崩溃。所以我只想向 android 12 用户发送通知。 firebase FCM可以吗?
【问题讨论】:
标签: android firebase firebase-cloud-messaging
我的应用程序以某种方式仅在 android 12 上崩溃。所以我只想向 android 12 用户发送通知。 firebase FCM可以吗?
【问题讨论】:
标签: android firebase firebase-cloud-messaging
检查设备是否为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
【讨论】: