Pinguin
Pinguin

Reputation: 23

Android BLE onScanResult is never called

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.

Upvotes: 1

Views: 804

Answers (2)

Avinash
Avinash

Reputation: 897

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.

Upvotes: 3

Bartosz Wilk
Bartosz Wilk

Reputation: 131

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.

Upvotes: 0

Related Questions