MinewBeaconAdmin 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"/>

The corresponding component registration under the AndroidManifest.xml file. As follows: AndroidStudio build.gradle add rely: dependencies { dependencies { testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.3.0' compile 'com.android.support:recyclerview-v7:23.3.0' compile 'org.greenrobot:eventbus:3.0.0' compile 'com.google.code.gson:gson:2.2.4' compile files('libs/minewBeaconAdmin.jar') } You can use this SDK to configure the surrounding Beacon for parameters such as uuid, major, minor, and so on. The SDK use four classes to achieve this part of the function.

Class Description

MinewBeaconManager

Scan devices manager class.

Features:

  1. start scan /stop scan
  2. get in range devices/get all devices around
  3. get bluetooth state
  4. listen device in/out state
  5. update scanned devices
  6. listen bluetooth state change
  7. on/off ConnectService

MinewBeacon

Scanned device model

All of these properties are read-only, and the underlying will periodically update the latest data for each device if it does not leave the scan range.

Features:

  1. Export device data to JSON string;
  2. Support import JSON string;

MinewBeaconConnection

The connection state between the device and the phone, and the protect class for the data update

Each instance corresponds to an instance of MinewBeacon and MinewBeaconSetting (connection state).

Features:

  1. Connect to a device / disconnect a device
  2. Update the property "MinewBeaconSetting" to the device (callback method returns whether the update was successful)

MinewBeaconSetting

Connected model

This class can only be connected in the Connection instance and the connection is successful after the acquisition, some attributes can be modified, modified after a temporary cache, only through the Connection instance successfully updated to the device changes will take effect.

Features:

  1. Export device data to JSON string;
  2. Support import JSON string;

Instructions

Scan devices

The MinewbeaconManager can start scan, and the SDK generates a MinewBeacon instance for the scanned device;


// 1.get MinewBeaconManager instance
MinewBeaconManager mMinewBeaconManager = MinewBeaconManager.getInstance(this);
//set callback
mMinewBeaconManager.setMinewbeaconManagerListener(new MinewBeaconManagerListener() {});

//2.start ConnectService
mMinewBeaconManager.startService();

// 3.start scan
mMinewBeaconManager.startScan();

// 4.Get the scan data update by callback method
// This method is used to retrieve the latest scan data for the surrounding device
- void onRangeBeacons(List<MinewBeacon> beacons);

/* If you want to listen the device out of the state, you can achieve the following methods */

// listen disappeared devices
- void onDisappearBeacons(List<MinewBeacon> beacons);

// listen new devices
- void onAppearBeacons(List<MinewBeacon> beacons);

/* listen bluetooth change */
// bluetooth state:on,off,none
// only work on bluetooth state on.
- void onUpdateBluetoothState(BluetoothState state);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

Connection

If you want to connect to the device, you need to use the MinewBeacon instance to generate a MinewBeaconConnection instance, through Connection to manage the connection / disconnect / update data.

// 1. Use a MinewBeacon instance to generate a Connection instance and set a callback monitor
MinewBeaconConnection minewBeaconConnection = new MinewBeaconConnection(context, minewBeacon);
minewBeaconConnection.setMinewBeaconConnectionListener(minewBeaconConnectionListener);
               
// 2. connect to device
 minewBeaconConnection.connect();

// 3.connection state
- void onChangeState(MinewBeaconConnection connection, ConnectionState state);
{
  //  When the connection is successful, the MinewBeaconSetting property of the connection instance is no longer empty, and the MinewBeaconSetting instance is the data obtained from the device
  switch (state) {
                case BeaconStatus_Connected:
                   minewBeaconConnection.setting.getMajor();
                    break;
                case BeaconStatus_ConnectFailed:
                case BeaconStatus_Disconnect:
                    break;
            }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Settings

When the state of the connection is connected, you can modify all the non-read attributes whose attributes are set. You can update to the Beacon device by simply executing method. You can know if the update has been successfully by callback method.

// 1.modify the setting attribute of connection
MinewbeaconSetting mMinewBeaconSetting = minewBeaconConnection.setting;
mMinewBeaconSetting.setUuid("FDA50693A4E24FB1AFCFC6EB07647825");

/*.....*/

// 2.Update changes to the device
// It should be noted that the parameters here are the current restart password for the Beacon device;
mMinewBeaconConnection.writeSetting("minew123");

// 3.Use the callback method to get a successful update to the device
- void onWriteSettings(MinewBeaconConnection connection, final boolean success) {
   if (success) {
               Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show();
           } else {
              Toast.makeText(getApplicationContext(), "Failed", Toast.LENGTH_SHORT).show();
                }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

More details ,refer to demo code.

Changelog

2018.11.20

Fixed bug for scanning.

Before

None.

Last Updated:: 2/19/2019, 2:33:20 PM