Проблема с уведомлением службы Forground для Android 8.1.0

[Я сталкиваюсь с той же проблемой, о которой уже сообщалось в stackoverflow] [1] При запуске службы forground в 8.1.0 я получил уведомление о сбое приложения. Журнал ошибок приведен ниже. Он отлично работает в Android 8.0 и Android 9. любой сталкивается с этим проблема.

    private void createNotificationChannel() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel serviceChannel = new NotificationChannel(
                    CHANNEL_ID,
                    "Foreground Service Channel",
                    NotificationManager.IMPORTANCE_DEFAULT
            );
            NotificationManager manager = getSystemService(NotificationManager.class);
            manager.createNotificationChannel(serviceChannel);
        }
    }



@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    String input = intent.getStringExtra("inputExtra");
    createNotificationChannel();
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this,
            0, notificationIntent, 0);
    Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setContentTitle("Foreground Service")
            .setContentText(input)
            .setSmallIcon(R.drawable.ic_stat_name)
            .setContentIntent(pendingIntent)
            .build();
    startForeground(1, notification);
    //do heavy work on a background thread
    //stopSelf();
    return START_NOT_STICKY;
}

Ошибка

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 defaults=0x0 flags=0x40 color=0x00000000 vis=PRIVATE)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
                at android.os.Handler.dispatchMessage(Handler.java:106)
                at android.os.Looper.loop(Looper.java:164)
                at android.app.ActivityThread.main(ActivityThread.java:6626)
                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:811)


  [1]: https://stackoverflow.com/questions/47531742/startforeground-fail-after-upgrade-to-android-8-1

person Hardik Patel    schedule 18.12.2019    source источник
comment
Также опубликуйте код уведомления   -  person Rahul Agrawal    schedule 18.12.2019
comment
@rahul Agrawal - я поделился своим кодом, пожалуйста, проверьте и дайте мне знать.   -  person Hardik Patel    schedule 18.12.2019
comment
проверьте эту ссылку   -  person Rahul Agrawal    schedule 18.12.2019
comment
Я не могу решить эту проблему, применив это решение.   -  person Hardik Patel    schedule 18.12.2019