Skip to content
Advertisement

android 10 is crashed when starting bluetooth service

in a couple of days before, I wrote some lines of code to connect application to a HC-05(a Bluetooth module) via a service. I know that a simple service can not be alive in a android 8+. so I modify my service using some free tutorials available on YouTube channels like the following:

https://www.youtube.com/watch?v=BXwDM5VVuKA

android 7- don’t have any problem but android 10 crashes when I clicked on “start service” button.

I bring for you some sections of my code.

onStartCommand in service:

JavaScript

and ‘createNotificationChannel()’ function in defined here:

JavaScript

onClick method for buttonIn (in order to start service) is here:

JavaScript

so can anyone solve this problem with android 10.

Advertisement

Answer

Android 10 has some limitation for implementing Bluetooth. For example, you need to allow some permission related to location. Below text is adopted from the following website:

https://www.journaldev.com/28028/android-10-location-permissions

Android 10 Location Permissions

With the introduction of Android 10, besides the dialog UI, the way of handling location permissions has also changed. Now the user is allowed to choose whether they want location updates when the app is in the background. For that a new permission needs to be declared in the Manifest file:

Calling this along with COARSE_LOCATION would pop up a dialog with three options:

1-Always Allow 2-Allow only while using the app 3-Deny

So the problem was that. Now by adding those permission, my problem solved.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement