05-20 17:25:42.825 7493-7493/com.xxxxxx.xxxxx E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxxxxx.xxxxx, PID: 7493
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: null
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)
05-20 17:25:42.826 7493-7493/com.xxxxxx.xxxxx E/UncaughtException: android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: null
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)
Asked
Active
Viewed 5,395 times
0

piet.t
- 11,718
- 21
- 43
- 52

Amritesh Kumar
- 207
- 1
- 5
- 16
-
solve the problem by using below code.., – Amritesh Kumar May 20 '18 at 17:50
-
String channelId; @RequiresApi(api = Build.VERSION_CODES.O) private void startForegroundNew() { channelId = createNotificationChannel(); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId); Notification notification = notificationBuilder.setOngoing(true) .setSmallIcon(R.mipmap.ic_launcher) .setCategory(Notification.CATEGORY_SERVICE) .build(); startForeground(101, notification); } – Amritesh Kumar May 20 '18 at 17:51
-
@RequiresApi(Build.VERSION_CODES.O) private String createNotificationChannel(){ String channelId = "my_service"; String channelName = "My Background Service"; NotificationChannel chan = new NotificationChannel(channelId,channelName, NotificationManager.IMPORTANCE_NONE); chan.setLightColor(Color.BLUE); chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); – Amritesh Kumar May 20 '18 at 17:52
-
notificationManager.createNotificationChannel(chan); return channelId; } – Amritesh Kumar May 20 '18 at 17:52
-
use this solution https://stackoverflow.com/questions/47531742/startforeground-fail-after-upgrade-to-android-8-1 – Mohamed Ramadan May 29 '18 at 12:37
-
Already solved the problem – Amritesh Kumar May 30 '18 at 10:54