RemoteServiceException:Android 8.0中的startForeground的错误通知

时间:2018-10-01 13:02:34

标签: android service android-8.0-oreo

我正在尝试在应用程序处于后台运行时启动startForeground服务,但出现此错误。

notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        System.out.println("ChannelID: Sip Service:000:"+nChannel);
        try {
            notificationManager.createNotificationChannel(nChannel);
        }catch (Exception e ){
            e.printStackTrace();
        }
    }

当我尝试创建通知频道时,应用崩溃了。

android.app.RemoteServiceException:错误的startForeground通知:java.lang.RuntimeException:服务通知的无效通道:Notification(channel = null pri = 0 contentView = null振动= null声音= null smartAlertCount = 0x0默认值= 0x0标志= 0x40颜色= 0x00000000 vis = PRIVATE)                                                                                   在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1768)                                                                                   在android.os.Handler.dispatchMessage(Handler.java:106)                                                                                   在android.os.Looper.loop(Looper.java:164)                                                                                   在android.app.ActivityThread.main(ActivityThread.java:6501)                                                                                   在java.lang.reflect.Method.invoke(本机方法)                                                                                   在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:438)                                                                                   在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

0 个答案:

没有答案