MinewBeacon Android Software Development Kit Guide

New Project

Android Studio Settings:

targetSdkVersion Version choose 21

Place the minewBeaconScan.jar into the libs folder, and then in the current project under the build.gradle file configuration items in the dependencies new content, as follows compile files ('libs / minewBeaconScan.jar').

Eclipse Settings:

targetSdkVersion Version choose 21

Place the scanBeacon.jar into the libs folder, right-click the project propeties, select Java build Path, add the minewBeaconScan.jar dependency in the Library option.

When the targetSdkVersion version is greater than or equal to 23, the need for dynamic application permissions.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
1
2

Permissions required for SDK:

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>

The corresponding component registration under the AndroidManifest.xml file. As follows: ​ more details, please refer to demo.

Start Developing

The MinewBeaconManager (as Manager below) is used to scan and stop scan the surrounding Bluetooth device, which generates a corresponding Minewbeacon (as Beacon below) instance for each Bluetooth device. When the Manager scans to a Bluetooth device, it continuously monitors the data update of the Bluetooth device and the status of the devices (the device with no data update in ten seconds is considered to be the device that disappeared and scanned for the first time Device is considered to be the device), while the Manager class can also monitor the Bluetooth state changes and call back to the corresponding proxy instance. The following is the relevant code.

1.get Manager instance and set call back listener:

MinewBeaconManager mMinewBeaconManager = MinewBeaconManager.getInstance(this);
mMinewBeaconManager.setDeviceManagerDelegateListener(new MinewBeaconManagerListener() {});
1
2

2.scan device:

mMinewBeaconManager.startScan();
1

3.update scanned devices:

// Get continuous device data update, this method callback once every 1 second, and only when the scan to the device will callback.
public void onRangeBeacons(final List<MinewBeacon> minewBeacons);
1
2

4.get data from MinewBeacon:

For the data versatility, we use the MinewBeaconValue (as BeaconValueIndex below) to unify all data types, value can correspond to the string, integer, float,boolean type, and so on.Each index corresponds to a value, as follows:

Get data from Beacon
// get uuid
mMinewBeacon.getBeaconValue(BeaconValueIndex.MinewBeaconValueIndex_UUID).getStringValue();
// get major
mMinewBeacon.getBeaconValue(BeaconValueIndex.MinewBeaconValueIndex_Major).getStringValue();
// get minor
mMinewBeacon.getBeaconValue(BeaconValueIndex.MinewBeaconValueIndex_Minor).getStringValue();
1
2
3
4
5
6
7

Schedule: ValueIndex and DataType

index Data Name Data Type Remarks
BeaconValueIndex_UUID uuid stringValue
BeaconValueIndex_Name Name stringValue
BeaconValueIndex_Major major intValue
BeaconValueIndex_Minor minor intValue
BeaconValueIndex_WechatId Wechat Id intValue Partial support
BeaconValueIndex_Mac mac address stringValue Partial support
BeaconValueIndex_RSSI rssi intValue
BeaconValueIndex_BatteryLevel battery intValue
BeaconValueIndex_Temperature temperature floatValue Partial support
BeaconValueIndex_Humidity humidity floatValue**** Partial support
BeaconValueIndex_Txpower txPower intValue
BeaconValueIndex_InRange range boolValue
BeaconValueIndex_Connectable connectable boolValue

Follow the corresponding index , get the desired data.

More Infomation,refer demo code

Listen range state

//If the device does not have data updates within 8 seconds, this device is considered to have disappeared and the device will disappear in this callback, this method every 5 seconds a cycle.

public void onDisappearBeacons(List<MinewBeacon> minewBeacons) {
                for (MinewBeacon minewBeacon : minewBeacons) {
                    String deviceName = minewBeacon.getBeaconValue(BeaconValueIndex.MinewBeaconValueIndex_Name).getStringValue();
                    Toast.makeText(getApplicationContext(), deviceName + "  out range", Toast.LENGTH_SHORT).show();
                }
            }
}

//The device that was first scanned or disapproved after being re-scanned is considered to be a new device, and the newly device will be in this callback, which is a cycle every 3 seconds.
  public void onAppearBeacons(List<MinewBeacon> minewBeacons) {

  }
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Listen the status of the Bluetooth module updates, Bluetooth status a total of three:

BluetoothState:BluetoothStatePowerOn(bluetooth on),BluetoothStatePowerOff(bluetooth off),BluetoothStateNotSupport(not support bluetooth 4.0)

//Due to the user or the system changes the Bluetooth switch, can be monitored in the following ways:
  public void onUpdateBluetoothState(BluetoothState state) {

  }
1
2
3
4

Get bluetooth state by checkBluetoothState method:

BluetoothState bluetoothState = mMinewDeviceManager.checkBluetoothState();
1

Class Description

MinewBeacon

Every device corresponds to a MinewBeacon, and there is only one method for obtaining the information of the device through the corresponding Index:

public MinewBeaconValue getBeaconValue(NS_ENUM ns_enum);
1

Example,get UUID:

minewBeacon.getBeaconValue(NS_ENUM.MinewBeaconValueIndex_UUID).getStringValue;
1

// correspond Enum // !!!Data must be obtained for each device's data type

public enum BeaconValueIndex {
  MinewBeaconValueIndex_UUID,  // UUID

  MinewBeaconValueIndex_Major,   // major

  MinewBeaconValueIndex_Minor,   // minor

  MinewBeaconValueIndex_Name,   // name

  MinewBeaconValueIndex_RSSI,   // RSSI

  MinewBeaconValueIndex_BatteryLevel,  // battery

  //MinewBeaconValueIndex_Temperature,  // temperature Not available yet

//MinewBeaconValueIndex_Humidity,   // humidity Not available yet

  MinewBeaconValueIndex_TxPower,  // TxPower

  MinewBeaconValueIndex_InRage  // in range

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

MinewBeaconValue

MinewBeaconValue: Obtain all instances of this data from the device. Obtain data in strict accordance with the data type.

//  int data
private int intValue;

// float data
private float floatValue;

// string data
private String stringValue;

//boolean data
private boolean bool;

// byte[] data
private byte[] dataValue;

BluetoothState

public enum  BluetoothState {
    BluetoothStatePowerOn, //bluetooth on

    BluetoothStatePowerOff, //bluetooth off

    BluetoothStateNotSupported,//not support bluetooth 4.0
}
1
2
3
4
5
6
7

##MinewBeaconManagerListener

MinewBeaconManager Interface。

// Found the new devices, the function callback every 3 seconds
void onAppearBeacons(List<MinewBeacon> minewBeacons);

// When the device disappears, call back once every second.
void onDisappearBeacons(List<MinewBeacon> minewBeacons);

//Callback data update function, callback once per second
void onRangeBeacons(List<MinewBeacon> minewBeacons);

//Bluetooth state update
void onUpdateState(BluetoothState state);

##MinewBeaconManager Device management class, used to scan the device and update the device status. // MinewBeaconManagerListener Interface

public void setDeviceManagerDelegateListener(MinewBeaconManagerListener minewBeaconManagerListener) {
}

// instance

public static MinewBeaconManager getInstance(Context context) {}
1

// get bluetooth state

public BluetoothState checkBluetoothState() {}
1

// scan device

public void startScan() throws Exception {}
1

// stop scan

public void stopScan() {}
1

// all scanned devices

public static List<MinewBeacon> scannedBeacons;
1

// in range devices

public static List<MinewBeacon> inRangeBeacons;
1

Changelog

2019.07.17

Fixed the exception for "java.lang.NegativeArraySizeException".

2018.11.20

Fixed bug for scanning.

2016.11.29

Add support for temperature and humidity sensor data.

Last Updated:: 7/17/2019, 4:26:20 PM