Search code examples
androidserviceandroid-notificationsupgraderos

Fail to Upgrade to Android 8.1


i have an existing project would i like upgrading from Android 8.0 to 8.1, but it failed. I reading the changes on Android 8.1, but i dont know what is exactly the problem. I have some failure in my logcat which you can see here:

    --------- beginning of crash
04-12 08:57:55.605 3530-3530/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.teleoperation, PID: 3530
    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=0x50 color=0x00000000 vis=PRIVATE)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1768)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        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)

EDIT: I found some interesting staff in the sourcecode. This application is working with the ros-library. I found this in the my programm:

public class ControlActivity extends RosActivity{
public ControlActivity() {
    super("RosAndroidExample", "RosAndroidExample");
}

This part of the code make the notification, but i dont know what i can do, to solve this problem

I hope this is enough information to solve my problem. When you need any kind of infomation please let me know.


Solution

  • From https://developer.android.com/guide/topics/ui/notifiers/notifications.html

    Starting in Android 8.0 (API level 26), all notifications must be assigned to a channel or it will not appear. By categorizing notifications into channels, users can disable specific notification channels for your app (instead of disabling all your notifications), and users can control the visual and auditory options for each channel—all from the Android system settings (figure 11). Users can also long-press a notification to change behaviors for the associated channel.

    Follow the steps in https://developer.android.com/training/notify-user/build-notification.html to make your notifications work for Android 8 and below.