Skip to content

Commit

Permalink
fix(android): petermetz#417 startAdvertising does not honor MeasuredP…
Browse files Browse the repository at this point in the history
…ower
  • Loading branch information
aircable authored and petermetz committed May 11, 2019
1 parent fcbe463 commit 96a86d2
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/android/LocationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (action.equals("isAdvertising")) {
isAdvertising(callbackContext);
} else if (action.equals("startAdvertising")) {
startAdvertising(args.optJSONObject(0), callbackContext);
startAdvertising(args, callbackContext);
} else if (action.equals("stopAdvertising")) {
stopAdvertising(callbackContext);
} else if (action.equals("isBluetoothEnabled")) {
Expand Down Expand Up @@ -1168,16 +1168,35 @@ public PluginResult run() {

}

private void startAdvertising(final JSONObject arguments, CallbackContext callbackContext) throws JSONException {
private void startAdvertising(final JSONArray args, CallbackContext callbackContext) throws JSONException {
debugLog("Advertisement start START BEACON ");
debugLog(arguments.toString(4));
debugLog(args.toString(4));
/*
Advertisement start START BEACON
[
{
"identifier": "beaconAsMesh",
"uuid": "e80300fe-ff4b-0c37-5149-d9f394b5ca39",
"major": 0,
"minor": 30463,
"notifyEntryStateOnDisplay": true,
"typeName": "BeaconRegion"
},
7
]
*/

JSONObject arguments = args.optJSONObject(0); // get first object
String identifier = arguments.getString("identifier");

//For Android, uuid can be null when scanning for all beacons (I think)
final String uuid = arguments.has("uuid") && !arguments.isNull("uuid") ? arguments.getString("uuid") : null;
final String major = arguments.has("major") && !arguments.isNull("major") ? arguments.getString("major") : null;
final String minor = arguments.has("minor") && !arguments.isNull("minor") ? arguments.getString("minor") : null;

// optinal second member in JSONArray is just a number
final int measuredPower = args.length() > 1 ? args.getInt(1) : -55;

if (major == null && minor != null)
throw new UnsupportedOperationException("Unsupported combination of 'major' and 'minor' parameters.");

Expand All @@ -1191,7 +1210,7 @@ public PluginResult run() {
.setId2(major) // Major for beacon
.setId3(minor) // Minor for beacon
.setManufacturer(0x004C) // Radius Networks.0x0118 Change this for other beacon layouts//0x004C for iPhone
.setTxPower(-56) // Power in dB
.setTxPower(measuredPower) // Power in dB
.setDataFields(Arrays.asList(new Long[] {0l})) // Remove this for beacon layouts without d: fields
.build();
debugLog("[DEBUG] Beacon.Builder: "+beacon);
Expand Down

0 comments on commit 96a86d2

Please sign in to comment.