Hi there.
i´m testing the app in a phone wih andoid 8 onwards and appears to me the next exception
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=1 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 backgroundColor=0x00000000 vis=PRIVATE)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1790)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6651)
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:810)
for try to fix the problem i develop the next code
class ForegroudService: Service() {
override fun onBind(intent: Intent?): IBinder? {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onCreate() {
super.onCreate()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForeground()
} else {
startForeground(1, Notification())
}
}
@RequiresApi(Build.VERSION_CODES.O)
fun startForeground() {
val NOTIFICATION_CHANNEL_ID = "com.estimote.indoorapp"
val channelName = "My Background Service"
val chan = NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, IMPORTANCE_HIGH)
chan.lightColor = Color.BLUE
chan.lockscreenVisibility = Notification.VISIBILITY_PRIVATE
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
manager.createNotificationChannel(chan)
val notificationBuilder = Builder(this, NOTIFICATION_CHANNEL_ID)
val notification = notificationBuilder.setOngoing(true)
.setSmallIcon(R.drawable.logo_app)
.setContentTitle("Find IT \u00AE")
.setContentText("Geoposicionamiento de interiores")
.setVisibility(VISIBILITY_PUBLIC)
.setChannelId(NOTIFICATION_CHANNEL_ID)
.setOnlyAlertOnce(true)
.setPriority(PRIORITY_HIGH)
.setCategory(CATEGORY_SERVICE)
.build()
startForeground(2, notification)
}
}
but i don’t know if is missing somethig because it the code execute but after activate the gps location permision the app crashes and this throws me the same exception
help me please for fix this problem for mi app can operate in all andoid API aviable versions
Best Regards.