Firebase通知未在后台或应用程序关闭时收到



该应用在封闭或背景中未接收通知。下面是我的服务课,可以处理通知。该通知仅在唯一的应用程序运行时才能正常工作。

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG = "MyFMService";
    Random random = new Random();
    int NOTIFICATION_ID = random.nextInt(9999 - 1000) + 1000;
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        sendNotification();

    }
    private void sendNotification() {
        Intent intent = new Intent(this, NotificationDisplay.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_bouddha_icon)
                .setContentTitle("Bouddha Meridian School")
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
    }
}

您是否下载了Google-service.json并放置在应用程序文件夹中?请按照此示例进行参考:http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-messaging-gcm-php-and-mysql/

当应用在MessageRecieve类的背景中时,您必须在执行有效载荷发送有效载荷Similer时从服务器上进行处理。

{
    "to" : "zzzzz",
     "notification": {
     "body": "",
     "title": "",
    "icon": ""
},
"data" : {
 "name" : ""
}
  }

相关内容

  • 没有找到相关文章

最新更新