Estimote / Android-Fleet-Management-SDK

Estimote Fleet Management SDK for Android
https://developer.estimote.com
MIT License
836 stars 451 forks source link

Mashmallow support #128

Closed CoreFloDev closed 9 years ago

CoreFloDev commented 9 years ago

Hi,

It seems that there is some missing permissions on the SDK for Mashmallow. I tried the same application on two devices one on 6.0 and the other on 5.1.

On the 5.1, everything is working fine, the SDK and the estimote application to configure the beacon.

On the 6.0, the estimote application is working but when I use the SDK, I get this error from a BeaconManager.MonitoringListener() :

10-19 10:40:09.807 7538-7558/com.tengio.biketracker D/BluetoothAdapter: startLeScan(): null
10-19 10:40:09.844 7538-7558/com.tengio.biketracker D/BluetoothAdapter: STATE_ON
10-19 10:40:09.849 7538-7550/com.tengio.biketracker D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=5
10-19 10:40:09.854 7538-7550/com.tengio.biketracker W/Binder: Caught a RuntimeException from the binder stub implementation.
10-19 10:40:09.854 7538-7550/com.tengio.biketracker W/Binder: java.lang.SecurityException: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to get scan results
10-19 10:40:09.854 7538-7550/com.tengio.biketracker W/Binder:     at android.os.Parcel.readException(Parcel.java:1599)
10-19 10:40:09.854 7538-7550/com.tengio.biketracker W/Binder:     at android.os.Parcel.readException(Parcel.java:1552)
10-19 10:40:09.854 7538-7550/com.tengio.biketracker W/Binder:     at android.bluetooth.IBluetoothGatt$Stub$Proxy.startScan(IBluetoothGatt.java:772)
10-19 10:40:09.854 7538-7550/com.tengio.biketracker W/Binder:     at android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper.onClientRegistered(BluetoothLeScanner.java:324)
10-19 10:40:09.854 7538-7550/com.tengio.biketracker W/Binder:     at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:56)
10-19 10:40:09.854 7538-7550/com.tengio.biketracker W/Binder:     at android.os.Binder.execTransact(Binder.java:453)
10-19 10:40:16.895 7538-7558/com.tengio.biketracker D/BluetoothAdapter: stopLeScan()
10-19 10:40:16.896 7538-7558/com.tengio.biketracker D/BluetoothAdapter: STATE_ON
10-19 10:40:46.900 7538-7558/com.tengio.biketracker D/BluetoothAdapter: startLeScan(): null

Am i missing something or it is an error from the SDK ?

heypiotr commented 9 years ago

Take a look at our Notification template for Android:

https://cloud.estimote.com/#/apps/add/notification

It shows how to request the appropriate permissions, the code to do that is in the MainActivity class.

Coming Soon™: we'll be updating Android tutorials and might add some helper methods to the SDK to request these permissions without you having to write all that code.

pwittchen commented 9 years ago

I've handled that problem in my smaller, personal project called ReactiveBeacons. Problem is described here: https://code.google.com/p/android/issues/detail?id=190372. It looks that BLE scan in Android 6 requires Location permissions in order to start scan.

To fix this problem, you have to do the following things:

You can also handle permissions with the new permission model introduced in API 23 (Android 6). If you want to do it in old-fashioned (pre-Marshmallow) way, you can simply add permissions to the Manifest and set targetApi to 22 (Lollipop).

Please note that you will not see any beacons until you enable Location in your phone as well as Bluetooth.

wiktor commented 9 years ago

It is more complicated than that. I'm already working on permissions and let me draw bigger picture.

On Android M it is as you had written when your app is targeting SDK 23. Although you need one of location permissions, no need to have both.

If your app is targeting <23 and is run on Android L or earlier, you need to acquire one of the location permissions only for background scanning.

See source code of Android M: https://android.googlesource.com/platform/packages/apps/Bluetooth/+/master/src/com/android/bluetooth/Utils.java#277

wiktor commented 9 years ago

All done: https://github.com/Estimote/Android-SDK/releases/tag/0.9.4

jgqandsh commented 8 years ago

I did the same like pwittchen said. First, I add
uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION" uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" at AndroidManifest.xml and I clicked build.gradle, my targetSdkVersion is 24, and minSdkVersion 21. So I changed the targetSdkVersion from 24 to 22. The code worked succesful.