为了账号安全,请及时绑定邮箱和手机立即绑定

如何在Firebase中的后台应用时处理通知

如何在Firebase中的后台应用时处理通知

qq_笑_17 2019-05-27 15:01:21
如何在Firebase中的后台应用时处理通知这是我的清单    <service android:name=".fcm.PshycoFirebaseMessagingServices">         <intent-filter>             <action android:name="com.google.firebase.MESSAGING_EVENT" />         </intent-filter>     </service>     <service android:name=".fcm.PshycoFirebaseInstanceIDService">         <intent-filter>             <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />         </intent-filter>     </service>当应用程序处于后台并且通知到达时,默认通知将会运行并且不会运行我的代码onMessageReceived。这是我的onMessageReceived代码。如果我的应用程序在前台运行,而不是在后台应用程序时,则调用此方法。如何在应用程序处于后台时运行此代码?// [START receive_message]@Overridepublic void onMessageReceived(RemoteMessage remoteMessage) {     // TODO(developer): Handle FCM messages here.     // If the application is in the foreground handle both data and notification messages here.     // Also if you intend on generating your own notifications as a result of a received FCM     // message, here is where that should be initiated. See sendNotification method below.     data = remoteMessage.getData();     String title = remoteMessage.getNotification().getTitle();     String message = remoteMessage.getNotification().getBody();     String imageUrl = (String) data.get("image");     String action = (String) data.get("action");     Log.i(TAG, "onMessageReceived: title : "+title);     Log.i(TAG, "onMessageReceived: message : "+message);     Log.i(TAG, "onMessageReceived: imageUrl : "+imageUrl);     Log.i(TAG, "onMessageReceived: action : "+action);     if (imageUrl == null) {         sendNotification(title,message,action);     } else {         new BigPictureNotification(this,title,message,imageUrl,action);     }}// [END receive_message]
查看完整描述

4 回答

  • 4 回答
  • 0 关注
  • 1401 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信