【发布时间】:2017-04-25 11:04:30
【问题描述】:
我正在尝试从 FCM 发送推送通知。但无法在我的 android 设备中接收。 起初您可以在图像中看到它没有被初始化,但后来初始化成功。 我可以获取 FCM 注册 ID,但无法获取推送消息。
这里是截图:
OnReceive 方法:
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// checking for type intent filter
if (intent.getAction().equals(Config.REGISTRATION_COMPLETE)) {
// gcm successfully registered
// now subscribe to `global` topic to receive app wide notifications
FirebaseMessaging.getInstance().subscribeToTopic(Config.TOPIC_GLOBAL);
displayFirebaseRegId();
} else if (intent.getAction().equals(Config.PUSH_NOTIFICATION)) {
// new push notification is received
String message = intent.getStringExtra("message");
Toast.makeText(getApplicationContext(), "Push notification: " + message, Toast.LENGTH_LONG).show();
txtMessage.setText(message);
}
}
};
我正在使用AndroidHive 的这个示例,并且我也尝试在不同版本的不同设备上对其进行测试。
如果有人能提供一些想法,那将对我非常有帮助。
【问题讨论】:
-
你如何发送推送通知?
-
来自谷歌的 fcm
-
我的意思是使用您自己的服务器或 fcm 控制台?
-
我是从 FCM 的控制台发送的
-
不需要使用 Brodcast Receiver 只需使用 public class MyFcm extends FirebaseMessagingService
标签: android firebase push-notification firebase-cloud-messaging