FCM не уведомляет о oreo, когда приложение находится на переднем плане (ниже oreo оно работает) - PullRequest
0 голосов
/ 02 декабря 2018

Я хочу получать уведомления FCM на свой телефон.Я использую код ниже.Теперь моя проблема в том, что, когда я нахожусь на Android Oreo и приложение работает на переднем плане, я не получаю сообщение (но на Android 7, например, он работает нормально!).Что я должен изменить, чтобы заставить его работать?Фон и когда приложение убито работает как на ОС.

public class MyFirebaseMessagingService extends FirebaseMessagingService {

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);

    //if the message contains data payload
    //It is a map of custom keyvalues
    //we can read it easily
    if(remoteMessage.getData() != null){

        sendNotification(remoteMessage);
    }

}

private void sendNotification(RemoteMessage remoteMessage) {
    Map<String, String> data = remoteMessage.getData();
    String title = remoteMessage.getNotification().getTitle();
    String body = remoteMessage.getNotification().getBody();

    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    String NOTIFICATION_CHANNEL_ID = "TestID";

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){

        @SuppressLint("WrongConstant")
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Notification", NotificationManager.IMPORTANCE_HIGH);

        notificationChannel.setDescription("Description");
        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(Color.BLUE);
        notificationChannel.setVibrationPattern(new long[]{0,1000,500,1000});

    }

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,NOTIFICATION_CHANNEL_ID);

    notificationBuilder.setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setWhen(System.currentTimeMillis())
            .setSmallIcon(R.drawable.app_icon)
            .setTicker("Ticker")
            .setContentTitle(title)
            .setContentText(body)
            .setContentInfo("info");

    notificationManager.notify(1,notificationBuilder.build());


}
}

Спасибо!

...