connectivity-samples icon indicating copy to clipboard operation
connectivity-samples copied to clipboard

Missing permission request

Open vitabr opened this issue 7 years ago • 7 comments

Hi, i just run project on Android 7 and it didn't work( didn't show any ~BLE devices during scan) because of Binder exception: 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:883) at android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper.onClientRegistered(BluetoothLeScanner.java:375) at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:56) at android.os.Binder.execTransact(Binder.java:453)

After manually adding of : <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> and manually turning on location permission thru app settings, application started to work and show BLE devices around.

vitabr avatar Feb 15 '18 12:02 vitabr

Conclusion: project missing Location permission and check for granted permissions on Android 6+

vitabr avatar Feb 15 '18 12:02 vitabr

Here is the source code with the manifest file fixed and the request to access permissions in the onCreate(). android-BluetoothLeGatt-master 2.zip

gmelcer avatar Apr 14 '18 20:04 gmelcer

Thanks for that fix, I'm a newbie trying to get my head around BLE data transfer. This has helped a lot!

Awesome!

Automateme2 avatar May 17 '18 03:05 Automateme2

Had the same issue and that fixed it, thanks a lot :)

olix86 avatar May 23 '18 19:05 olix86

I added the permission in manifest and turned on the location,but still it doesnt display any ble device name

rupikat avatar Dec 18 '18 11:12 rupikat

GOOGLE. My dude. Please freaking fix your project and add: <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

stuartsoft avatar Feb 26 '19 05:02 stuartsoft

GOOGLE. My dude. Please freaking fix your project and add: <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Adding the permission will not be enough, because this is a runtime permission and the target SDK is 27. They either have to lower the targetSDKVersion or add some code to ask for this runtime permission.

Which this PR seems to contain already: https://github.com/googlesamples/android-BluetoothLeGatt/pull/53/files

So yeah, Google! Just have look at this PR and merge it.

biafra23 avatar Mar 04 '19 11:03 biafra23