San*_*idi 9 android firebase firebase-cloud-messaging
在Firebase控制台中,我看到了使用app"com.example"(其中com.example是应用名称)向User Segement发送通知的选项.
如图所示:
但是如何使用FCM REST API从服务器端执行此操作:
小智 5
我找到了一个解决方案,您可以将您的应用订阅到特定主题,例如您的FirebaseInstanceIdService类中的应用包名称,这样您就可以发送数据按
{
"to" : "/topics/your_package_name",
"data" : {
"key1" : "value 1",
"key2": "value 2",
...
}
}
Run Code Online (Sandbox Code Playgroud)
这是在FirebaseInstanceIdService类中将您的应用订阅到主题的代码
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService
{
private final String TAG="your_tag";
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
FirebaseMessaging.getInstance().subscribeToTopic("your_app_package_name");
}
}
Run Code Online (Sandbox Code Playgroud)
它为我工作
您实际上需要向该主题发送消息..所有订阅该主题的成员都会收到您的消息..
只需查看链接..
https://developers.google.com/cloud-messaging/topic-messaging
| 归档时间: |
|
| 查看次数: |
10281 次 |
| 最近记录: |