52

I am getting a toast saying "Developer warning for package com.google.android.apps.messaging" when sending an MMS using Android Messages ver 2.3.063.

In logs

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 services ver 11.3.02
Android Messages 2.3.063
Android 8.0.0

Anyone up there to help me ? Screenshot

Shabbir Panjesha
  • 1,851
  • 5
  • 20
  • 29
  • I went through this https://stackoverflow.com/questions/44489657/android-o-reporting-notification-not-posted-to-channel-but-it-is but nothing works for me – Shabbir Panjesha Aug 14 '17 at 05:45
  • If the app is targeting Android O, all the notifications must be posted using [Notification Channel][1]. Otherwise, the notifications are dropped and this "Developer warning" toast will be displayed in Android O running devices. [1]: https://developer.android.com/preview/features/notification-channels.html – Bob Aug 14 '17 at 06:39
  • But I believe Android messages app would have added notification channel support. – Bob Aug 14 '17 at 06:43
  • Share the code snippet how are you showing the notification. – azizbekian Aug 14 '17 at 09:25
  • Related post if you're using API level 26+ - [NotificationCompat.Builder doesn't accept 2nd argument](https://stackoverflow.com/q/50765964/465053) – RBT Sep 03 '18 at 04:51

3 Answers3

86

As it is written in Android Documentation:

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

If you target Android O and post a notification without specifying a valid notifications channel, the notification fails to post and the system logs an error.

To solve this issue you need to create a NotificationChannel.

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);

And then assign it to your Notification like this:

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:

In case you want to use NotificationCompat here is a simple example:

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

In fact you have to use Notification Builder in order to set channel id via setChannelId();

Moshe Katz
  • 15,992
  • 7
  • 69
  • 116
Milad Moosavi
  • 1,587
  • 10
  • 20
  • what is .setChannelId in Notification – Mohit Singh Aug 16 '17 at 10:31
  • 2
    It just binds the notification channel you just created to the notification.builder. – Milad Moosavi Aug 16 '17 at 10:59
  • i posted my question please help me [https://stackoverflow.com/questions/45711925/failed-to-post-notification-on-channel-null-target-api-is-26](https://stackoverflow.com/questions/45711925/failed-to-post-notification-on-channel-null-target-api-is-26) – Mohit Singh Aug 16 '17 at 11:10
  • Where/when should I create the notification channel? Once, at app start? In App#onCreate()? – Ridcully Nov 21 '17 at 07:59
  • @Ridcully It depends on where you are making notification.It can be onCreate() of activity or onCreateView() of fragment. – Milad Moosavi Nov 21 '17 at 08:04
  • You can create channel once for every context or as many notifications as you're trying to build. – Milad Moosavi Nov 21 '17 at 08:06
  • I'm now creating the channel one time in Application's onCreate() and it works fine. – Ridcully Nov 21 '17 at 09:06
  • 1
    I was getting an error: `Wrong 1st argument type. Found: 'java.lang.String', required: 'int'` in the line `mNotificationManager.notify(id, notification);` So after passing `notifyID` instead of `id` I am now receiving notifications. – Hunterr Jul 23 '18 at 18:13
  • FYI, `NotificationCompat.Builder(Context context)` is now deprecated, use `NotificationCompat.Builder(Context context, String channelId)` instead (and you won't need `.setChannelId(id)`) – cramill Nov 16 '18 at 18:24
6

Messages on Toast and Logcat talk about you should be paid attention to 2 items and them order:

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

Also NotificationManager notifManager and NotificationChannel mChannel are created only once.

There are required setters for Notification:

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

See the example in On Android 8.1 API 27 notification does not display.

Andy Sander
  • 1,888
  • 1
  • 13
  • 16
0

easy

companion object {
    private val TAG = simpleClassName

    // The id of the channel.
    private val channelId = "my_channel_01"
    private val notifyID: Int = 1
    private val importance = NotificationManagerCompat.IMPORTANCE_DEFAULT
}


val mChannel = NotificationChannelCompat.Builder(channelId, importance).apply {
    setName("channel name") // Must set! Don't remove
    setDescription("channel description")
    setLightsEnabled(true)
    setLightColor(Color.RED)
    setVibrationEnabled(true)
    setVibrationPattern(longArrayOf(100, 200, 300, 400, 500, 400, 300, 200, 400))
}.build()


NotificationManagerCompat.from(context).createNotificationChannel(mChannel)
val notification: Notification = NotificationCompat.Builder(context, channelId)
    .setSmallIcon(R.drawable.ic_launcher_foreground)
    .setContentTitle(sender)
    .setContentText(body)
    .build()
NotificationManagerCompat.from(context).notify(notifyID, notification)
Ashton
  • 2,425
  • 2
  • 22
  • 26