android / connectivity-samples

Multiple samples showing the best practices in connectivity on Android.
Apache License 2.0
1.66k stars 1.32k forks source link

BLE not scanning for devices #25

Open NivedithaKabbur opened 7 years ago

NivedithaKabbur commented 7 years ago

I tried to run the code with SDK version 25 and Build tool version 25.0.3. Have got the error as below.

06-20 17:25:45.382 29678-29678/com.example.android.bluetoothlegatt D/BluetoothAdapter: startLeScan(): null
06-20 17:25:45.385 29678-29678/com.example.android.bluetoothlegatt D/BluetoothAdapter: STATE_ON
06-20 17:25:45.395 29678-29692/com.example.android.bluetoothlegatt D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=5
06-20 17:25:45.400 29678-29692/com.example.android.bluetoothlegatt W/Binder: Caught a RuntimeException from the binder stub implementation.
                                                                             java.lang.SecurityException: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to get scan results
                                                                                 at android.os.Parcel.readException(Parcel.java:1620)
                                                                                 at android.os.Parcel.readException(Parcel.java:1573)
                                                                                 at android.bluetooth.IBluetoothGatt$Stub$Proxy.startScan(IBluetoothGatt.java:772)
                                                                                 at android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper.onClientRegistered(BluetoothLeScanner.java:324)
                                                                                 at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:56)
                                                                                 at android.os.Binder.execTransact(Binder.java:453)
06-20 17:25:47.404 29678-29879/com.example.android.bluetoothlegatt D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
06-20 17:25:47.442 29678-29879/com.example.android.bluetoothlegatt I/Adreno: QUALCOMM build                   : 166ada0, Ifd751822f5
                                                                             Build Date                       : 01/26/16
                                                                             OpenGL ES Shader Compiler Version: XE031.06.00.05
                                                                             Local Branch                     : AU12_SBA
                                                                             Remote Branch                    : 
                                                                             Remote Branch                    : 
                                                                             Reconstruct Branch               : 
06-20 17:25:47.454 29678-29879/com.example.android.bluetoothlegatt I/OpenGLRenderer: Initialized EGL, version 1.4
06-20 17:25:55.381 29678-29678/com.example.android.bluetoothlegatt D/BluetoothAdapter: stopLeScan()

Have got it resolved by adding the following permissions in the manifest.

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

hemapanjakshram commented 7 years ago

By adding this above code also not working

NivedithaKabbur commented 7 years ago

What is the error you are getting?

zeevox commented 7 years ago

You need the location permission to scan for devices. If you are on API 23+, make sure you request permission as I mentioned in android/android-BluetoothLeGatt#38 comment 2

fmatosqg commented 7 years ago

As I posted on issue android/android-BluetoothLeGatt#38 I'll try to continue the pending work on PR android/android-BluetoothLeGatt#20, apparently the only problem is a merge conflict on gradle that should be solved with a pull rebase.

SZooo commented 2 years ago

You need the location permission to scan for devices. If you are on API 23+, make sure you request permission as I mentioned in googlearchive/android-BluetoothLeGatt#38 comment 2

Why not commit the code