iammert / RadioPlayerService

Android service library which uses AAC Player. Ready to use Radio Player Service.
254 stars 90 forks source link

Bad notification for startForeground: invalid channel for service notification #69

Closed colorgold closed 4 years ago

colorgold commented 5 years ago

This is a great library, but after upgrading to Android API 28, I keep getting an error stating, "Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null..." I have already set "android.permission.FOREGROUND_SERVICE" in manifest as well as, "android:usesCleartextTraffic="true"." But, my app still crashes.

Any help will be greatly appreciated.

Thanks!

joelelangovan1985 commented 5 years ago

Pls update the Notification with channels to avoid the crash.

colorgold commented 5 years ago

Thank you for replying. I am currently using an older version of the RadioPlayerService, but of course, it does not have the new features that the most current one has, which I want to use. So, if you don’t mind explaining, how do I go about updating the notification with channels? I will explain what I have tried so far:

-In my fragment class, I’ve implemented the RadioPlayerService and I am using RadioManager. -I tried creating my own service, but this just creates a new notification unrelated to the RadioPlayerService. -I’ve reviewed the classes in the library, but I don’t know how to edit them or implement them in my project

Again, thank you so much for reaching out; this has already given me a new idea of where to start looking for a fix.


From: Joel ELangovan notifications@github.com Sent: Saturday, December 22, 2018 12:11:30 AM To: iammert/RadioPlayerService Cc: colorgold; Author Subject: Re: [iammert/RadioPlayerService] Bad notification for startForeground: invalid channel for service notification (#69)

Pls update the Notification with channels to avoid the crash.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/iammert/RadioPlayerService/issues/69#issuecomment-449548310, or mute the threadhttps://github.com/notifications/unsubscribe-auth/Ar20K9wgAWtn_bWFoEFwgbVLb7v3COwwks5u7c0SgaJpZM4ZZicF.

colorgold commented 4 years ago

I was able to fix it: String channelName = "My background Service"; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, ``channelName, NotificationManager.IMPORTANCE_DEFAULT); chan.setLightColor(Color.BLUE); chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);

        mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        assert mNotificationManager != null;
        mNotificationManager.createNotificationChannel(chan);`