jamesfalkner / liferay-android-beacons

A Titanium Appcelerator module to interact with iBeacons via the Radius Networks' iBeacon native android library
Other
46 stars 27 forks source link

Error on Android 6.0 (API 23) #17

Open Astrovic opened 8 years ago

Astrovic commented 8 years ago

I'm trying module on my nexus 5x, but I get this error message in the log:

[WARN] :   Binder: Caught a RuntimeException from the binder stub implementation.
[WARN] :   Binder: java.lang.SecurityException: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to get scan results
[WARN] :   Binder:  at android.os.Parcel.readException(Parcel.java:1620)
[WARN] :   Binder:  at android.os.Parcel.readException(Parcel.java:1573)
[WARN] :   Binder:  at android.bluetooth.IBluetoothGatt$Stub$Proxy.startScan(IBluetoothGatt.java:772)
[WARN] :   Binder:  at android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper.onClientRegistered(BluetoothLeScanner.java:324)
[WARN] :   Binder:  at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:56)
[WARN] :   Binder:  at android.os.Binder.execTransact(Binder.java:453)
rwuttke commented 8 years ago

There are several fixes for this problem.

First need to get a newer version of Radius.jar from Radius Networks and update the code to support it as the namespaces have changed.

http://developer.radiusnetworks.com/2016/04/12/beacon-apps-on-android-6-update.html

Then you will need to add code to your application to request the Permissions for LOCATION.

Here is the catch, your app will need a custom version of 5.2.0.GA SDK, because it doesn't have the Permissions for Android baked in.

For more information, please look here

http://gitt.io/component/ti.permissions

http://stackoverflow.com/questions/35890378/how-to-request-run-time-recording-permission-on-android-6-0

rwuttke commented 8 years ago

I have created a new version locally of the Library to support this, may have to actually use GitHub and create a Pull Request.

Astrovic commented 8 years ago

OK, thank you, I solved asking localization allowed after starting the app :) Another question. Is there a way to check if the bluetooth status is on or off? Because I noticed that if when I start module the bluetooth is not enabled (status off), if I enable subsequently the bluetooth, module don't works. So the bluetooth must already be running before you start tracking beacons. Thanks :)

rwuttke commented 8 years ago

The is a checkAvailability which basically says "Is BT on or existing".

You can use this function.

One thing you could do is setup an interval and call this.

Something like this at it's core. Obviously you will need to track that you have shown this otherwise each time the even fires it will show it if the user has not enabled bluetooth and or locations.

if (!TiBeacons.checkAvailability()) {
    //alert('Either Bluetooth is turned off, or your device does not support Bluetooth LE');

    var alertDlg = Ti.UI.createAlertDialog({
        title : 'Bluetooth LE Required',
        message : 'Please enable Bluetooth',
        buttonNames : ['Cancel', 'Open Settings'],
        cancel : 0
    });

    alertDlg.addEventListener('click', function(e) {
        if (!e.cancel) {
            var settingsIntent = Titanium.Android.createIntent({
                action : 'android.settings.BLUETOOTH_SETTINGS'
            });
            Ti.Android.currentActivity.startActivity(settingsIntent);
        }
    });

    alertDlg.show();
}

Obviously this only works for Bluetooth, but as you now need location, you will need to do the a similar thing for Locations.

Astrovic commented 8 years ago

Thank you very much for the advice! It is an excellent solution :)

roelandp commented 8 years ago

@rwuttke would be great if you could provide the complete fix... With the updated radius.jar etc? I've implemented this in an app which already asked for location for other purposes, so I'm curious it will work out of the box, with targetSDK 23 ....

I guess posting your updates as pull-requests would really help me and some others... Maybe even a new dist-version, eg. 0.5?

kind regards, roeland

rwuttke commented 8 years ago

@roelandp I will try to find some time ASAP to get that done.

tityrus commented 8 years ago

The current code in the repository doesn't work with Android SDK 23 + Titanium SDK 5.2.0.GA either. We made some changes to get that working, but haven't tested on Android 6 with the new permissions system.

So @rwuttke if you can do the update for Android 6 permissions then great. If not I might be able to help at least with SDK 23 + Titanium 5.2.0.GA support.

roelandp commented 8 years ago

Really?

I have built this module inside Android 6 (targetSDK 23) and had it checked via one of our testers with a Nexus 5x Android 6.0.1.

In the given app I have a check whether the 'bluetooth' is enabled / BLE works:

Ti.API.info(TiBeacons.checkAvailability()); Ti.API.info(TiBeacons.isReady());

This does actually work and respond upon switching bluetooth on / off (returns either a true / false) and I run this on the given page in a interval (up to a minute) and kills the interval whenever bluetooth is switching on. (and sets the color to 'green' and text to 'Bluetooth OK').

But I must say I do have the new android permissions in this app already built in at a earlier level for:

Because I mainly use this for 'GPS'-based tours.

Kind regards, Roeland

On 19 May 2016, at 18:53, Joris notifications@github.com wrote:

The current code in the repository doesn't work with Android SDK 23 + Titanium SDK 5.2.0.GA either. We made some changes to get that working, but haven't tested on Android 6 with the new permissions system.

So @rwuttke https://github.com/rwuttke if you can do the update for Android 6 permissions then great. If not I might be able to help at least with SDK 23 + Titanium 5.2.0.GA support.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/jamesfalkner/liferay-android-beacons/issues/17#issuecomment-220385714

PietroGranati commented 7 years ago

Hi everyone, I've noticed the same problem, form me android seems to see the region but not the beacons.

In fact an android 5 fires the event "proximity" but android 6 no

appinlet commented 6 years ago

@PietroGranati @roelandp @Astrovic @rwuttke

I've got the module working in a new Android app on version 6 using 6.2.0.GA and my rebuilt module at: https://github.com/RBAtkins0n/liferay-android-beacons

I have this code inside the app to request permission:

if (OS_ANDROID) { var permissions = ['android.permission.ACCESS_FINE_LOCATION']; Ti.Android.requestPermissions(permissions, function(e) { if (e.success) { Ti.API.info("SUCCESS"); } else { Ti.API.info("ERROR: " + e.error); } }); }

And this is what I've got in my tiapp.xml (some of these entries are specific to my app and may not be needed).

`

</android>`
appinlet commented 6 years ago

Instructions are added to the docs.

@jamesfalkner this issue can be marked resolved