3

I have this crash in production which I cannot reproduce and have no idea why it's happening.

android.app.RemoteServiceException: (Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null tick defaults=0x0 flags=0x4a color=0x00000000 vis=PRIVATE))
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1771)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

That sounds to me like the channel wasn't created but I create the channel every time before I create the notification.

I'm not even sure that it's happening in this part of the code but this is the only place where I'm starting a foreground service so I assume I'm on the right track

Here's the code

String channelId = NotificationChannelConstants.MAIN_NOTIFICATION_CHANNEL_ID;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    String channelName = NotificationChannelConstants.MAIN_NOTIFICATION_CHANNEL_NAME;
    NotificationChannel chan = new NotificationChannel(channelId,
                channelName, NotificationManager.IMPORTANCE_LOW);
    chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
    NotificationManager service = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    service.createNotificationChannel(chan);
}

notificationBuilder = new NotificationCompat.Builder(this, channelId)
            .setWhen(System.currentTimeMillis())
            .setSmallIcon(R.drawable.sb_unknown)
            .setContentTitle(getString(R.string.app_name))
            .setTicker(getString(R.string.app_name)).setContentIntent(broadcastIntent)
            .setContentText(mNotificationText)
            .setAutoCancel(false)
            .setOngoing(true)
            .setOnlyAlertOnce(true);

startForeground(R.id.notification, notificationBuilder.build());
noev
  • 980
  • 8
  • 26
  • This crash occur on Android 8.1? – Alex Nov 27 '18 at 11:17
  • @Alex Yes only on 8.1 – noev Nov 27 '18 at 11:19
  • Did you added permission in manifest? – Alex Nov 27 '18 at 11:27
  • I have added it yesterday but haven't pushed it to production yet. I know it's required for the foreground service to run but this crash message sounds like it would have nothing to do with it? – noev Nov 27 '18 at 11:31
  • Do you able to reproduce this crash on your device/emulator running on Android 8.1? If yes, you can test if the missing permission fixed the issue. – Alex Nov 27 '18 at 11:33
  • No unfortunately I can't reproduce it locally. – noev Nov 27 '18 at 11:44
  • @noev add this permission in manifest `` – nimi0112 Nov 27 '18 at 13:56
  • I have added permission in the manifest, still I am having this issue but the strange thing is all of them are happening in Samsung devices. – CopsOnRoad Apr 03 '19 at 15:57
  • @CopsOnRoad do you solved your problem ? I faced same issue and also on many Samsung devices. – hoang8f Apr 08 '19 at 18:28
  • @hoang8f I searched and found that the real issue is with Android SDK, I don't remember the link of the thread but all we can do is just WAIT till they come up with a fix. – CopsOnRoad Apr 09 '19 at 07:05

0 Answers0