Менеджер уведомлений перестал работать - PullRequest
0 голосов
/ 29 июня 2018

Эта проблема была решена. Смотрите мое решение ниже.

Я только что завершил преобразование моего приложения для обмена сообщениями в FCM. Вы можете увидеть процесс, через который я прошел здесь . Теперь, когда это сделано, мои уведомления больше не работают. Если мой FirebaseMessagingService получает сообщение и главное приложение не активно, я создаю уведомление на телефоне, на котором я работаю.

Это правильно работает в течение многих лет на GCM. Когда я прослеживаю код, все выполняется нормально - в трее не появляется никаких уведомлений. Я не могу себе представить, что Firebase будет делать с этим.

Это код, который вызывается из FirebaseMessagingService. Этот код работает годами просто отлично. , .

public static void raiseNotification( String username, String mesText, int count)
{
    String message = "From: " + username + " " + mesText;
    if (count > 1)
    {
        count--;
        message = message +  " + " + count + " more";
    }



    NotificationCompat.Builder b = new NotificationCompat.Builder(GlobalStuff.GCT);

    Intent intent = new Intent(GlobalStuff.GCT, MainActivity.class);
    intent.putExtra("whattodo", username);
    intent.setAction(Long.toString(System.currentTimeMillis())); //just to make it unique from the next one
    PendingIntent pIntent = PendingIntent.getActivity(GlobalStuff.GCT, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);


    b.setContentTitle("New SafeTalk Message")
            .setSmallIcon(R.drawable.ticon)
            .setContentText(message)
            .setTicker("New SafeTalk Message")
            .setContentIntent(pIntent)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setAutoCancel(true);
    //.addAction(R.drawable.smallredball, "Read Now", pIntent)
    //.addAction(R.drawable.smallquestion, "hello there", pIntent);

    NotificationManager mgr = (NotificationManager)GlobalStuff.GCT.getSystemService(NOTIFICATION_SERVICE);
    mgr.notify(0, b.build());
}

1 Ответ

0 голосов
/ 30 июня 2018

Эта проблема решена. После того, как вы напишите приложение для Android, Google заставит вас работать полный рабочий день до конца вашей жизни, просто чтобы он работал. Они ломают демонов перемен . Оказывается, эта проблема с уведомлением не имеет ничего общего с Firebase (которая сама является матерью всех критических изменений).

Google изменил требования к отправке уведомлений в Oreo. Google разработал это изменение так, чтобы, если ваше приложение работало на Oreo, и вы не внесли изменения, ваше уведомление просто не будет работать - надеюсь, никто не создавал важные уведомления. В Oreo требуется идентификатор канала.

Вот код, который работает в Oreo. , .

На самом деле этот код не полностью работает в Oreo. Смотрите мой следующий пост относительно уведомлений в Oreo

   private void sendNotification(String messageBody) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);

        String channelId = getString(R.string.default_notification_channel_id);
        Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, channelId)
                .setSmallIcon(R.drawable.ic_stat_ic_notification)
                .setContentTitle("FCM Message")
                .setContentText(messageBody)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        // Since android Oreo notification channel is needed.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(channelId,
                    "Channel human readable title",
                    NotificationManager.IMPORTANCE_DEFAULT);
            notificationManager.createNotificationChannel(channel);
        }

        notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
    }
...