web-dev-qa-db-de.com

NotificationChannel-Problem in Android O

Beim Senden einer MMS mit Android Messages ver 2.3.063 .

In Protokollen

08-12 16:57:52.368  7661  7682 W Notification: Use of stream types is deprecated for operations other than volume control
08-12 16:57:52.368  7661  7682 W Notification: See the documentation of setSound() for what to use instead with Android.media.AudioAttributes to qualify your playback use case
08-12 16:57:52.369  1604  3146 E NotificationService: No Channel found for pkg=com.google.Android.apps.messaging, channelId=miscellaneous, id=5, tag=null, opPkg=com.google.Android.apps.messaging, callingUid=10130, userId=0, incomingUserId=0, notificationUid=10130, notification=Notification(channel=miscellaneous pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x8 color=0xff2a56c6 vis=PRIVATE)
08-12 16:57:52.375  1604  3094 D CompatibilityInfo: mCompatibilityFlags - 0
08-12 16:57:52.375  1604  3094 D CompatibilityInfo: applicationDensity - 480
08-12 16:57:52.375  1604  3094 D CompatibilityInfo: applicationScale - 1.0
08-12 16:57:52.378  7661  7682 I BugleNotifications: Notifying for tag = null, type = RESIZING_NOTIFICATION_ID, notification = Notification(channel=miscellaneous pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x8 color=0xff2a56c6 vis=PRIVATE)
08-12 16:57:52.381  7661  8893 W Notification: Use of stream types is deprecated for operations other than volume control
08-12 16:57:52.381  7661  8893 W Notification: See the documentation of setSound() for what to use instead with Android.media.AudioAttributes to qualify your playback use case
08-12 16:57:52.384  1604  1618 E NotificationService: No Channel found for pkg=com.google.Android.apps.messaging, channelId=miscellaneous, id=5, tag=null, opPkg=com.google.Android.apps.messaging, callingUid=10130, userId=0, incomingUserId=0, notificationUid=10130, notification=Notification(channel=miscellaneous pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x8 color=0xff2a56c6 vis=PRIVATE)
08-12 16:57:52.384   880  1657 W StreamHAL: Error from HAL stream in function get_presentation_position: Operation not permitted
08-12 16:57:52.387  7661  8893 I BugleNotifications: Notifying for tag = null, type = RESIZING_NOTIFICATION_ID, notification = Notification(channel=miscellaneous pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x8 color=0xff2a56c6 vis=PRIVATE)
08-12 16:57:52.390  1604  1647 E NotificationService: No Channel found for pkg=com.google.Android.apps.messaging, channelId=miscellaneous, id=5, tag=null, opPkg=com.google.Android.apps.messaging, callingUid=10130, userId=0, incomingUserId=0, notificationUid=10130, notification=Notification(channel=miscellaneous pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x48 color=0xff2a56c6 vis=PRIVATE)

Google Play-Dienste Version 11.3.02
Android-Nachrichten 2.3.063
Android 8.0.0

Ist da oben jemand, der mir hilft? Screenshot

36

Wie es in der Android Dokumentation geschrieben ist:

https://developer.Android.com/preview/features/notification-channels.html

Wenn Sie Android O) als Ziel festlegen und eine Benachrichtigung veröffentlichen, ohne einen gültigen Benachrichtigungskanal anzugeben, schlägt die Benachrichtigung fehl und das System protokolliert einen Fehler.

Um dieses Problem zu beheben, müssen Sie einen NotificationChannel erstellen.

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

// The id of the channel.
String id = "my_channel_01";

// The user-visible name of the channel.
CharSequence name = getString(R.string.channel_name);

// The user-visible description of the channel.
String description = getString(R.string.channel_description);

int importance = NotificationManager.IMPORTANCE_LOW;

NotificationChannel mChannel = new NotificationChannel(id, name,importance);

// Configure the notification channel.
mChannel.setDescription(description);

mChannel.enableLights(true);
// Sets the notification light color for notifications posted to this
// channel, if the device supports this feature.
mChannel.setLightColor(Color.RED);

mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});

mNotificationManager.createNotificationChannel(mChannel);

Und weisen Sie es dann Ihrer Benachrichtigung wie folgt zu:

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

// Sets an ID for the notification, so it can be updated.
int notifyID = 1;

// The id of the channel.
String CHANNEL_ID = "my_channel_01";

// Create a notification and set the notification channel.
Notification notification = new Notification.Builder(MainActivity.this)
    .setContentTitle("New Message")
    .setContentText("You've received new messages.")
    .setSmallIcon(R.drawable.ic_notify_status)
    .setChannelId(CHANNEL_ID)
    .build();

// Issue the notification.
mNotificationManager.notify(id, notification);

Update:

Für den Fall, dass Sie NotificationCompat verwenden möchten, ist dies ein einfaches Beispiel:

NotificationCompat.Builder mBuilder;
mBuilder = new NotificationCompat.Builder(getApplicationContext())
    .setSmallIcon(R.mipmap.ic_launcher_icon)
    .setContentTitle("Title")
    .setContentText("Text")
    .setOngoing(true)
    .setChannelId(id);

Tatsächlich müssen Sie den Notification Builder verwenden, um die Kanal-ID über setChannelId () festzulegen.

70
Milad Moosavi

Nachrichten auf Toast und Logcat, die über Sie sprechen, sollten auf 2 Artikel und deren Reihenfolge geachtet werden:

  1. NotificationChannel mChannel = new NotificationChannel(id, name, importance);
  2. builder = new NotificationCompat.Builder(this, id);

Auch NotificationManager notifManager und NotificationChannel mChannel werden nur einmal erstellt.

Für die Benachrichtigung sind folgende Setter erforderlich:

builder.setContentTitle() // required  
       .setSmallIcon()    // required 
       .setContentText()  // required  

Siehe das Beispiel in On Android 8.1 API 27-Benachrichtigung wird nicht angezeigt .

4
Andy Sander