1

I have developed a little BLE App for Android which connects with my mobile music Box. Everything works fine on my phone (Android 9). So I bought a tablet (Android 9) and there onScanResult is never called, but when I search with Android board-function I see the Bluetooth device.

ACCESS_FINE_LOCATION
BLUETOOTH 
BLUETOOTH_ADMIN 

is set and Location is set to on.

Ajeett
  • 814
  • 2
  • 7
  • 18
Pinguin
  • 23
  • 4

2 Answers2

3

if your bluetooth is on then give runtime permission of , ACCESS_FINE_LOCATION and ACCESS_CORSE_LOCATION and still you are facing this issue then gps on and restart scanning its working fine.

Required permission for BLE,

   <uses-permission android:name="android.permission.BLUETOOTH"/>
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
   <uses-permission   android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

and check gps is enable or not

       private fun enableLocation(): Boolean {
    val service = activity?.getSystemService(Context.LOCATION_SERVICE) as   LocationManager
    val enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER)
    return enabled
}

and if return false then

val intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
                    startActivity(intent)

for enable your gps progrmatically and if true then scan your device.

Avinash
  • 867
  • 4
  • 11
  • You are right. isProviderEnabled shows false. But where can I turn it on. The Location is on and with your method Action_Location_Source_Settings I don't get to the GPS and Location is already enabled. – Pinguin Jan 20 '20 at 07:47
  • ACTION_LOCATION_SOURCE_SETTINGS is used for go to your gps setting page.. enable it and restart process again. – Avinash Jan 20 '20 at 07:51
  • I have on this page only one menu point and this is Location and it's set to on. Should I have another button or menupoint for GPS? – Pinguin Jan 20 '20 at 08:01
  • no on click of check if(enableLocation()) if it is true scan your device else you can show a dialog for enable gps permission if it press ok call intent with ACTION_LOCATION_SOURCE_SETTINGS. – Avinash Jan 20 '20 at 08:21
  • https://stackoverflow.com/questions/9928256/how-to-turn-on-the-gps-on-android – Avinash Jan 20 '20 at 08:24
  • Many thanks for your Answers. I have found my Problem. You cannot check for GPS. Then you get Always false. When you delete isProviderEnabled(GPS_Provider) then it works correctly… That is very strange, but it is like it is! – Pinguin Jan 20 '20 at 08:31
  • alright but its working fine for my side in all condition and i have check every time for status of gps before scanning.if you are facing any issue regarding BLE then tell me. – Avinash Jan 20 '20 at 08:38
0

ACCESS_FINE_LOCATION could be declared in manifest but it's not treated as granted by default. Have you requested for granting this permission in runtime? If not, request for it in runtime or just go to permissions section in your app settings and grant it manually.

Bartosz Wilk
  • 131
  • 6