Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ti 9+ support and added bind/unbind methods #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

dependencies {
// Add the module's library dependencies here.
// See: https://developer.android.com/studio/build/dependencies
implementation 'org.altbeacon:android-beacon-library:2+'
}
Binary file added dist/com.liferay.beacons-android-4.0.1.zip
Binary file not shown.
10 changes: 6 additions & 4 deletions documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Place the ZIP file into your project's root directory, and declare the module an
...
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest package="[YOUR_APP_PACKAGE_NAME]">
<uses-sdk android:minSdkVersion="21"
android:targetSdkVersion="26"/>
<uses-permission
android:name="android.permission.BLUETOOTH"/>
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission
android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
<application>
<service android:enabled="true"
android:exported="true"
Expand Down Expand Up @@ -103,10 +103,11 @@ var TiBeacons = require('com.liferay.beacons');
android.os.RemoteException: The IBeaconManager is not bound to the service. Call iBeaconManager.bind(IBeaconConsumer consumer) and wait for a callback to onIBeaconServiceConnect()
```

Instead of guessing when the service is ready, we can check using the following method:
Instead of guessing when the service is ready, we can check using the following method adn force the bind:

```
var handle;
TiBeacons.bindBeaconService(); // This will force the bind to prevent TiBeacons.isReady() from always remaining false
handle = setInterval(function(){
if(!TiBeacons.isReady())
return;
Expand All @@ -119,7 +120,7 @@ handle = setInterval(function(){
}, 1000);
```

2. See if it's supported on the device via `TiBeacons.checkAvailability()` - If it is not, you should not attempt to call any other APIs, and somehow indicate that it's not supported in your app to the end user. The module
2. See if it's supported on the device via `TiBeacons.checkAvailability()` - If it is not, you should not attempt to call any other APIs, and somehow indicate that it's not supported in your app to the end user. The module

3. Decide whether you want auto-ranging, and turn it on via `TiBeacons.setAutoRange(true)` if you want it, or `TiBeacons.setAutoRange(false)` if not. The default is `true` (that is, auto-ranging is enabled).

Expand Down Expand Up @@ -184,6 +185,7 @@ To turn everything off:
```
TiBeacons.stopRangingForAllBeacons();
TiBeacons.stopMonitoringAllRegions();
TiBeacons.unbindBeaconService(); // to force unbind
```

### Objects passed to the callbacks
Expand Down
18 changes: 0 additions & 18 deletions java-sources.txt

This file was deleted.

7 changes: 3 additions & 4 deletions manifest
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@
# limitations under the License.
#

version: 2.0.0
version: 4.0.1
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86
architectures: arm64-v8a armeabi-v7a x86 x86_64
description: Enables Titanium apps supporting android to interact with iBeacons
author: James Falkner
license: Apache Software License 2.0
copyright: Copyright 2014 Liferay, Inc. All Rights Reserved.


# these should not be edited
name: liferay.beacons
moduleid: com.liferay.beacons
guid: 57bcb713-b5cd-4bb1-95d5-9141b6074802
platform: android
minsdk: 7.0.0.GA
minsdk: 9.0.0
21 changes: 21 additions & 0 deletions src/com/liferay/beacons/LiferayBeaconsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ public boolean isReady() {
return this.ready;
}

/**
* Binds the activity to the Beacon Service
*/
@Kroll.method
public void bindBeaconService() {
Log.d(TAG, "bindService");
iBeaconManager.bind(this);
}

/**
* Unbinds the activity to the Beacon Service
*/
@Kroll.method
public void unbindBeaconService() {
Log.d(TAG, "unbindService");
iBeaconManager.unBind(this);
}

/**
* Throttles down iBeacon library when app placed in background (but you have to
* detect this yourself, this module does not know when apps are put in background).
Expand Down Expand Up @@ -357,6 +375,9 @@ public void onDestroy(Activity activity)
}

public void onIBeaconServiceConnect() {
KrollDict e = new KrollDict();
e.put("message", "success");
fireEvent("serviceBound", e);

Log.d(TAG, "onIBeaconServiceConnect");
this.ready = true; //so we know the module is ready to setup event listeners
Expand Down