[英]Firebase push notification in android not working
我在Android中使用Firebase实现了推送通知,并且正在使用Firebase控制台接收推送通知。 但是,当我尝试通过发送设备令牌和服务器密钥连接到服务器时,则没有收到(来自服务器的)通知。
我们的服务器端团队已经过测试,并且可以正常使用,但是我的设备未收到推送通知(安装了应用程序的设备),并且我从Firebase收到了推送通知。
如何连接到服务器? 在Android中还是在创建google-services.json文件时出现问题?
使用Firebase推送通知时,有两种情况来处理数据有效负载(例如,您的“活动名称”等)。
情况1:当您的应用程序在前台运行(当前在屏幕上运行)时,您将从类中重写的onMessageReceived(RemoteMessage remoteMessage)
方法中的RemoteMessage object
获取数据有效负载, RemoteMessage object
方法必须扩展FirebaseMessagingService
类。
例如 :
public class FirebaseMessagingServiceHelper extends FirebaseMessagingService {
private final String TAG = "FirebaseMsgServiceHelper";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Map<String, String> dataPayload = null;
dataPayload = remoteMessage.getData();
}
}
情况2:当您的应用程序在后台运行时,您将获得数据有效载荷作为应用程序启动器Activity
附加目的。
例如 :-
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//get notification data info
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
//bundle must contain all info sent in "data" field of the notification
}
}
但是,这两种情况都不能正常工作时,我得到了名Activity
是应该当用户点击一个通知是开放的Notification Drawer
中click_action
在和数据有效载荷data
。
但是,当我的推杆下来的数据,它的工作对我罚款在两种情况下的一切ie
应用是否在前台或后台您的应用程序运行将接收数据有效载荷每次在RemoteMessage object
在onMessageReceived(RemoteMessage remoteMessage)
方法。
以下是我从哪里获得想法的链接。 Firebase FCM通知click_action有效负载
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.