MinewDoorLock Development Guide

This set of SDK only supports Bluetooth module devices from Minew. The SDK helps developers handle everything between the phone and the Bluetooth module, including: scanning devices, connecting devices, writing data to devices, receiving data from devices, and more.

Design instructions

Use device + manager mode in SDK.

Get Started

Development environment

  1. Android Studio
  2. minSdkVersion:19

Import to Project

  1. Add minewDoorlockLib.jar to the libs folder of the module and add the following statement to the build.gradle of the module (add the dependency directly):

    implementation files('libs/minewDoorlockLib.jar')
    
    1

    Or right click on the jar file and select Add as Library to add to the current module.

  2. The following permissions are required in AndroidManifest.xml. If targetSdkVersion is greater than 23, you need to do ** permission management** to get permission.

    <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_COARSE_LOCATION" />
    
    1
    2
    3
    4

Start development

Scanning stage

First you need to start Bluetooth and open the position switch, get the MLockBLEManager singleton, and set the required listener

//get manager instance
mLockBLEManager = MLockBLEManager.getInstance(this);

//set listener
mLockBLEManager.startScan(new ScanLockResultListener() {
    @Override
    public void onScanLockResult(@NonNull List<MLockModule> result) {
        //Monitor scan, add the scanned device to the list, 
        //and result represents all scanned unconnected lock devices
        
    }
});
1
2
3
4
5
6
7
8
9
10
11
12

Connect

There are two connection methods, which are divided into master/slave mode. Generally speaking, the connection mode of one interface setting only supports one type, and can be set when the interface is initialized. The setting method is:

//host
mLockBLEManager.getLockBleConnect().writeUnlockRecordFor(LockBleConnectImpl.mNOTIFYUnlockRecord);

//guest
mLockBLEManager.getLockBleConnect().writeUnlockRecordFor(LockBleConnectImpl.mADDUnlockRecord);
1
2
3
4
5

After the device is successfully connected, if the device is connected for the first time, you need to set a password. Otherwise, you need to verify the password. After the password is set or verified successfully, it starts to write 5 temporary passwords. These 5 temporary passwords can be used to unlock and can only be used once.

mMLockBLEManager.connect(module,mLockConnectListener);

mLockConnectListener = new LockConnectListener() {
    @Override
    public void onAuthStateChange(final boolean isAuthSuccess, final MLockModule mLockModule) {
        
    }

    @Override
    public void bindSetting(final MLockModule mLockModule) {
        
    }

    @Override
    public void bindPswFail(String macAddress) {
        
    }

    @Override
    public void disConnect() {
        
    }
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

The connection process needs to write a temporary unlock password, and can only use the temporary password successfully written to unlock. The listener write process is as follows:

mMLockBLEManager.setOnTempPswWriteListener(new OnTempPswWriteListener() {

    /**
     * Start writing temporary passwords, you can do some preparatory work here.
     */
    @Override
    public void onStartWriteTempPsw(final String macAddress) {
        
    }

    /**
     * Temporary password successfully written
     */
    @Override
    public void onWritePswSuccess(String macAddress, String... password) {
        
    }

    /**
     * Failed to write temporary password
     */
    @Override
    public void onWritePswFailure(String macAddress, String password) {

    }

    /**
     * The password is written successfully.
     */
    @Override
    public void onAllWriteSuccess(final String macAddress) {

    }
});
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

The final connection result can be obtained from the following listeners

mLockBLEManager.setLockModuleConnChange(new LockModuleConnChange() {
    @Override
    public void onLockConnChange(MLockModule device, ConnectionState status) {

    }
});
1
2
3
4
5
6

注意:The status returned inonLockConnChange(MLockModule, ConnectionState) has only three return values: DeviceLinkStatus_Connected, DeviceLinkStatus_ConnectFailed, DeviceLinkStatus_Disconnect, if needed, the other state is obtained in the LockConnectListener interface.

After the connection is completed, you can go to unlock, lock, unlock the lock, unbind, etc.

Unlocking and interlocking

  1. Set when the interface is initialized

    mLockBLEManager.getLockBleConnect().writeUnlockRecordFor(LockBleConnectImpl.mADDUnlockRecord);
    
    1
  2. Set the listener, monitor whether the unlock or lock is successful or failed, and lock the state after the lock or unlock

    mLockBLEManager.setOnUnlockListener(new OnUnlockListener() {
        @Override
        public void unlockSuccess(String macAddress) {
            
        }
    
        @Override
        public void unlockFailure(String macAddress) {
            
        }
    
        @Override
        public void lockSuccess(String macAddress) {
            
        }
    
        @Override
        public void lockFailure(String macAddress) {
            
        }
    
        @Override
        public void getLockStatus(String macAddress, final boolean lockStatus) {
    
        }
    });
    
    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
  3. It is best to first determine the current lock state, each time the connection will get the lock state, according to the lock state to determine whether the next operation is unlocked or locked

    String lockStatus = mLockBLEManager.getLockStatus().get(mMacAddress);
    if (lockStatus.equals(Constant.NOTIFY_LOCK_STATUS_UNLOCK)) {
        LogUtil.e("LockDetail", "will lock");
        MLockModuleOperate.lockByHost(mMacAddress, mLockModule.getPassword());
    } else if (lockStatus.equals(Constant.NOTIFY_LOCK_STATUS_LOCK)) {
        LogUtil.e("LockDetail", "will unlock");
        MLockModuleOperate.unlockByHost(mMacAddress, mLockModule.getPassword());
    } else {
        ToastUtil.showToast(getString(R.string.lock_status_exception));
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
Temporary password unlock
  1. The SDK supports unlocking the bound device (locked state)

    MLockModuleOperate.unlockByGuest(mLockModule.getMacAddress(), tempPassword);
    
    1
  2. The rest of the settings are the same as above

Get unlock record

  1. First set the unlock record operation mode

    mLockBLEManager.getLockBleConnect().writeUnlockRecordFor(LockBleConnectImpl.mNOTIFYUnlockRecord);
    
    1
  2. Set listener

    mLockBLEManager.setOnReadUnlockRecordListener(new OnReadUnlockRecordListener() {
        @Override
        public void readUnlockRecord(final Unlock unlock) {
    		
        }
    
        @Override
        public void readRecordComplete(final Unlock unlock) {
            
        }
    
        @Override
        public void newestUnlockRecord() {
            
        }
    
        @Override
        public void emptyUnlockRecord() {
            
        }
    });
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
  3. The lock storage capacity is limited, it is impossible to save too much data, and only 30 unlock records are saved. Each time the unlock record is read, if the local unlock record is already saved, the time of the last local unlock record is sent, sent in the format of yyyyMMddHHmmss, otherwise MLockModuleOperate.EMPTY_UNLOCK_RECORD is sent, as follows:

    MLockModuleOperate.readUnlockRecord(mMacAddress, "20190320144000");
    //or:
    MLockModuleOperate.readUnlockRecord(mMacAddress, 
                            MLockModuleOperate.EMPTY_UNLOCK_RECORD);
    
    1
    2
    3
    4

Unbind

Examples are as follows:

LockUtil.unbind(mLockModule, new LockOperationCallback() {
    @Override
    public void onOperation(final boolean success, BluetoothException mtException) {
		//unbind successfully
    }
});
1
2
3
4
5
6
Last Updated:: 1/19/2021, 3:19:00 PM