question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

android.app.remoteserviceexception: bad notification for startforeground

See original GitHub issue

#1234 Hi Exoplayer Team, I am getting errors with the latest version 2.15.1 when trying to show notifications in the notification tray. Why is this issue here? I am using the following code.

      notificationManager = new PlayerNotificationManager
                .Builder(this, NOTIFICATION_ID, PLAYBACK_ID)
                .setMediaDescriptionAdapter(mediaDescriptionAdapter)
//                .setChannelNameResourceId(2)
//                .setChannelDescriptionResourceId(2)
                .setNotificationListener(notificationListener)
                .build();

and in the notificationlistener my code is

    private final PlayerNotificationManager.NotificationListener notificationListener =
            new PlayerNotificationManager.NotificationListener() {

                @Override
                public void onNotificationCancelled(int notificationId, boolean dismissedByUser) {
                    if (dismissedByUser) {
                        stopSelf();
                    }
                }

                @Override
                public void onNotificationPosted(int notificationId, @NotNull Notification notification, boolean ongoing) {
                    Toast.makeText(getApplicationContext(), "n " + notificationId, Toast.LENGTH_SHORT).show();
                    if (!ongoing) {
                        stopForeground(true);
                    } else {
//                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
//                            startForeground(notificationId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK);
//                        } else {
//                            startForeground(notificationId, notification);
//                        }
                    }
                }
            };

the notification listener code works well in android 11 1 yeat back when I think I am using the 2.10.0 version, but now I think the issue is in android 11 only because of check-in version 9 and it works well. Please help me to fix it for my app because I have to publish an update of the app next week.

Hope you understand and help me to find out

Android Device - Redmi Note10S Android Version - 11

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
marcbaechingercommented, Nov 19, 2021

I marked this as a documentation candidate to document the constructor argument channelId in more detail/. It should say that the channel needs to be already created or else setChannelNameResourceId needs to be called.

0reactions
marcbaechingercommented, Dec 28, 2021

Closing this issue as the need for an existing channel has been documented and there wasn’t any more activity. Please reopen if this is still an issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

startForeground fail after upgrade to Android 8.1
After some tinkering for a while with different solutions i found out that one must create a notification channel in Android 8.1 and...
Read more >
Bad notification for startForeground crash on >= Android 8.1 ...
FATAL EXCEPTION: main android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel ...
Read more >
A bug in Android 9 allows app to start a foreground service ...
When app passes bad notification to the startForeground API, crash the app and DO NOT let app start foreground service, like all Android...
Read more >
Bad notification for startForeground: java.lang ... - 51CTO博客
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException,安卓开发8.1以上系统启动服务和通知报错 ...
Read more >
Bad notification for startForeground: java.lang.RuntimeException
[Android] android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found