我已将Fire基础云消息传递与我的应用程序集成.当我从firebase控制台发送通知时,如果app处于后台/未打开,那么我收到通知,
但当应用处于前台/开放时无法接收通知
所有建议都表示赞赏.
我的应用正在正确接收通知,但未能显示收到信息的通知(如果应用已打开).
注意:如果应用程序在后台,则会显示通知而不会出现任何问题.
我的代码:
我收到此方法的通知:
@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
Log.d(TAG, "From: " + remoteMessage.getFrom());
if(remoteMessage!=null)
{
String id = null;
String title = null;
String body = null;
String launchPage = null;
if(remoteMessage.getNotification()!=null)
{
title = remoteMessage.getNotification().getTitle();
body = remoteMessage.getNotification().getBody();
}
if(remoteMessage.getMessageId()!=null)
{
id = remoteMessage.getMessageId();
}
Log.i(TAG, "id: " + id);
Log.i(TAG, "title: "+ title);
Log.i(TAG, "body: " + body);
int notif_id = 0;
sendNotification(notif_id, title, body, launchPage);
}
}
Run Code Online (Sandbox Code Playgroud)
然后它调用这个(它应该显示我理解的通知):
private void sendNotification(int id, String title, String …Run Code Online (Sandbox Code Playgroud)