# MinewBeaconAdmin Android Software Development Kit Guide

# New Project

Android Studio Settings:

targetSdkVersion Version choose 33

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 Configuration

targetSdkVersion: Choose version 33 Place the minewBeaconAdmin.jar file into the 'libs' folder. Right-click on the project, select 'Java Build Path,' and add a dependency on minewDevice in the 'Library' section.

For targetSdkVersion greater than or equal to 23, you need to dynamically request permissions:

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

Required permissions for the current SDK:

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

For targetSdkVersion: Choose version 33

    <uses-permission android:name="android.permission.BLUETOOTH"
        android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
        android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN"
        tools:targetApi="s" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
1
2
3
4
5
6
7

Add service and receiver as follows:

<service android:name="com.minew.beaconset.ConnectService"/>

<receiver android:name="com.minew.beaconset.BluetoothChangedReceiver"
    android:exported="false">
    <intent-filter>
        <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
    </intent-filter>
</receiver>

1
2
3
4
5
6
7
8
9

For targetSdkVersion: Choose version 33 You must grant Bluetooth-related permissions to call Bluetooth-related APIs; otherwise, you will encounter errors. Change the receiver from a static broadcast to a dynamic broadcast, and call the registerBleChangeBroadcast() method in the corresponding logical code.

Add the following dependencies to your Android Studio's build.gradle file:

dependencies {
    implementation 'org.greenrobot:eventbus:3.0.0'
    implementation 'com.google.code.gson:gson:2.2.4'
    implementation files('libs/minewBeaconAdmin.jar')
}
1
2
3
4
5

You can use this SDK to configure parameters such as UUID, major, minor, etc., for nearby beacons. Four classes are used for this purpose.

# Class Overview

# MinewBeaconManager

A management class for scanning devices:

Functions:

  1. Start/stop scanning

  2. Get devices in the current scanning range/get all scanned devices

  3. Get the current Bluetooth state

  4. Listen for device entry/exit status (delegate callbacks)

  5. Update data of scanned devices (delegate callbacks)

  6. Listen for Bluetooth state changes (delegate callbacks)

  7. Start/stop connection service

# MinewBeacon

A data model class for scanned devices. All properties of this class are read-only, and the underlying data for each device will be periodically updated (if it hasn't left the scanning range).

Functions:

  1. Export device data as a JSON string
  2. Support importing JSON strings

# MinewBeaconConnection

A maintenance class for connection status and data updates between devices and Android devices. Each instance of this class corresponds to a MinewBeacon and MinewBeaconSetting instance when connected.

Functions:

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

# MinewBeaconSetting

A data model for device data after connecting. This class can only be obtained after a successful connection is initiated through the Connection instance. Some properties can be modified, and modifications will be temporarily cached. Only changes successfully updated to the device through the Connection instance will take effect.

Functions:

  1. Export data as a JSON string
  2. Import JSON strings

# Usage

# Scanning Devices

Use the MinewBeaconManager management class to initiate scanning. The SDK will generate MinewBeacon instances for devices found during scanning.

// 1. Get an instance of MinewBeaconManager and set a delegate object
MinewBeaconManager mMinewBeaconManager = MinewBeaconManager.getInstance(this);
// Set up callback listener
mMinewBeaconManager.setMinewbeaconManagerListener(new MinewBeaconManagerListener() {});

// 2. Start the connection service
mMinewBeaconManager.startService();

// 3. Initiate scanning
mMinewBeaconManager.startScan();

MinewBeaconManagerListener Interface Description:
// Bluetooth states: On, Off, Unknown
// It only works when Bluetooth is in the "On" state.
- void onUpdateBluetoothState(BluetoothState state);

// Listen for devices within range (appeared within 10 seconds).
- void onRangeBeacons(List<MinewBeacon> beacons);

// Listen for disappearing devices (disappeared after 10 seconds).
- void onDisappearBeacons(List<MinewBeacon> beacons);

// Listen for newly discovered devices.
- void onAppearBeacons(List<MinewBeacon> beacons);

/* Other methods of MinewBeaconManager */
// Actively retrieve all scanned devices.
- List<MinewBeacon> getScannedBeacons()

// Actively retrieve devices within range.
- List<MinewBeacon> getInRangeBeacons()

// Actively retrieve newly discovered devices.
- List<MinewBeacon> getNewMinewBeaconList()

// Set the interval time for the onRangeBeacons callback in milliseconds, default is 1000 milliseconds, minimum is 100 milliseconds.
mMinewBeaconManager.setRangeInterval(1000);

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
29
30
31
32
33
34
35
36
37
38

# 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;
// Modify/Add password,it will add password if device has no password, update password if device has a password
// (Warning/Note)!!!: the password string length must be 8, digits or letters,Otherwise, it may cause the device firmware to malfunction
mMinewBeaconConnection.writeSetting("minew123");

// 3.Use the callback method to get a successful update to the device
- void onWriteSettings(MinewBeaconConnection connection, final boolean success, boolean dissView) {
   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
19
20

# Device shutdown function

Currently only the B6-B001A version of the device has the shutdown function

// 1.Determine whether the shutdown function is turned off
MinewBeaconConnection mMinewBeaconConnection = MinewBeaconConnection.minewBeaconConnections.get(mac);

MinewbeaconSetting mMinewBeaconSetting = minewBeaconConnection.setting;
if (mMinewBeaconSetting.isPowerOff()) {//true:true: there is a shutdown function, false: there is no shutdown function

   //Shutdown button can be shown here
   
}

// 2. addListener
mMinewBeaconConnection.setMinewBeaconWriteListener(new MinewBeaconWriteListener() {
            @Override
            public void onPowerOff(final boolean success) {
                try {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (success) {
                                // When success device will not callback here , because The device has been turned off
				// You can refer to the code in the example on how to override the finish method
                            }else {
                                Log.e("tag", "DetilActivity " + "onPowerOff fail");
                            }
                        }
                    });
                }catch (Exception e){
                    Log.e("tag", e.getMessage());
                }
            }
        });


// 3. Send shutdown command,you must send device password
// It should be noted that the parameters here are the current restart password for the Beacon device;
mMinewBeaconConnection.writePowerOffByAuth(password);

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
29
30
31
32
33
34
35
36
37

More details ,refer to demo code.

# Changelog

# 2023.04.24

  • The interval time for scanning callback data can be set;

# 2023.02.02

  • Added shutdown function of B6-B001A version;

# 2022.04.20

  • Optimized for filtering irrelevant devices;
  • Added support for Beacon info broadcast frames;
  • Fix issues;

# 2018.11.20

Fixed bug for scanning.

# Before

None.

Last Updated:: 11/8/2024, 10:41:54 AM