大家好,我使用firebase从服务器接收推送通知。当应用程序运行时一切正常。我收到了通知,我会处理它并通过通知托盘显示它。看起来很完美。这是我的代码。应用程序关闭时的Firebase通知(问题)
public class FirebasePushService extends FirebaseMessagingService {
private static final String TAG = "FireBase main service ";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "Got Message: " + remoteMessage.getFrom());
try {
if (remoteMessage != null && remoteMessage.getNotification() != null
&& remoteMessage.getNotification().getBody() != null) {
String body = remoteMessage.getNotification().getBody();
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + body);
}
} catch (JSONException e) {
e.printStackTrace();
}
}}
清单代码。
<service android:name="app.asparagus.com.asparagus.firebase.FirebasePushService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
。问题在于应用程序关闭时。没有这个类的日志作品,什么都没有。但这里有一个有趣的部分。我可以从服务器看到整个JSON,并显示在通知托盘上(显示整个JSON对象)。真的没有得到我的代码中的错误。检查图像。 1-成功案例。