Не удается получить уведомления, если я запускаю свое приложение на устройстве Huawei - PullRequest
0 голосов
/ 18 июня 2019

Моя проблема в том, что если я запускаю свое приложение на устройстве Huawei, я не могу получить никакого уведомления, но если я запускаю свое приложение на другом устройстве, оно работает нормально, и вы найдете ниже код уведомления в моем FirebaseMessagingService:

    private void displayNotification(RemoteMessage.Notification notification, Map<String, String> data) {
        Random generator = new Random();
        String id = data.get("element");
        String type = data.get("type");
        Intent intent;
        intent = new Intent(this, Home.class);
        intent.putExtra("retour", type + "test");
        intent.putExtra("element_id", id);
        intent.setAction(Long.toString(System.currentTimeMillis()));
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);//RingtoneManager.TYPE_NOTIFICATION
        long[] pattern = {500, 500, 500, 500, 500, 500, 500, 500, 500};
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
        NotificationCompat.Builder notificationbuilder = new NotificationCompat.Builder(this);
        notificationbuilder.setContentTitle(notification.getTitle());
        notificationbuilder.setContentText(notification.getBody());
        notificationbuilder.setAutoCancel(true);
        notificationbuilder.setVibrate(pattern);
        notificationbuilder.setSound(defaultSoundUri);
        notificationbuilder.setSmallIcon(R.drawable.icoapp_and);
  notificationbuilder.setColor(getResources().getColor(R.color.colorAccent));
        notificationbuilder.setContentIntent(pendingIntent);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(generator.nextInt(), notificationbuilder.build());   }

1 Ответ

0 голосов
/ 18 июня 2019

Попробуйте следующий код для добавления канала в NotificationManager:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
     mChannel = new NotificationChannel(idChannel, 
     context.getString(R.string.app_name), importance);
     // Configure the notification channel.
     mChannel.setDescription(context.getString(R.string.alarm_notification));
     mChannel.enableLights(true);
     mChannel.setLightColor(Color.RED);
     mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 
     300, 200, 400});
     mNotificationManager.createNotificationChannel(mChannel);
} else {
     builder.setContentTitle(context.getString(R.string.app_name))
          .setPriority(NotificationCompat.PRIORITY_HIGH)
          .setColor(ContextCompat.getColor(context, R.color.transparent))
          .setVibrate(new long[]{100, 250})
          .setLights(Color.YELLOW, 500, 5000)
          .setAutoCancel(true);
}
...