Ich versuche, Benachrichtigungen für Android O-Version zu implementieren. Ich habe über Benachrichtigungsmanager und Kanäle gelesen. Daher möchte Android O immer noch keine Benachrichtigungen reproduzieren. Auf die Hauptaktivität in der PostCreate-Methode habe ich das geschrieben.Android O-Benachrichtigung wird nicht angezeigt
NotificationManager mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String CHANNEL_ID = "my_channel_01";
String CHANNEL_NAME = "my Channel Name";
int NOTIFICATION_ID = 1;
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent notificationPendingIntent = PendingIntent.getActivity(this, NOTIFICATION_ID,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationChannel notificationChannel = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
notificationChannel = new NotificationChannel(CHANNEL_ID,
CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.setShowBadge(true);
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
mNotifyManager.createNotificationChannel(notificationChannel);
}
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Notification myNotification = new NotificationCompat.Builder(MainActivity.this)
.setContentTitle("You have been notify")
.setContentText("This is your Notifiaction Text")
.setSmallIcon(R.drawable.ic_donut_large_black_24dp)
.setChannel(CHANNEL_ID)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setContentIntent(notificationPendingIntent)
.setAutoCancel(true)
.setSound(alarmSound)
.build();
mNotifyManager.notify(NOTIFICATION_ID, myNotification);
Toast.makeText(this, "accepted", Toast.LENGTH_SHORT).show();
Nach Build für 26. API es nicht Benachrichtigung schafft, Toast Nachricht Feuer und Protokolle sagen mir:
W/Mitteilung: Die Verwendung von Stream-Typen für andere Operationen als Lautstärkeregler ist veraltet W/Mitteilung: Lesen Sie die Dokumentation von setSound() für das, was mit android.media.AudioAttributes zu verwenden, anstatt Ihre Wiedergabe Use Case
Wie dieser Fehlerfall behandeln zu qualifizieren?
Upd. Nach einigen Nachforschungen habe ich festgestellt, dass 26 api einige Änderungen im Notification Builder verwendet. Jetzt akzeptiert es auch Chanelid. Also für 26 Builder mit zwei Parametern verwenden.
Mögliche Duplikat [Benachrichtigung nicht trotz Schaffung eines Kanals im Android O zeigt nach oben] (https://stackoverflow.com/questions/46255675/notification-not-showing-up -in-android-o-trotz-creating-a-channel) – Da2da2