MinewKeyfinder Android Software Development Kit Guide

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.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
1
2
3
4
5
6
7
8
9
10
11

The corresponding component registration under the AndroidManifest.xml file. As follows:

<service android:name="com.minew.device.service.ConnectService"/>
<receiver android:name="com.minew.device.BluetoothChangedReceiver">
        <intent-filter>
            <action android:name="android.bluetooth.adapter.action.STATE_CHANGED"/>
        </intent-filter>
</receiver>
1
2
3
4
5
6

AndroidStudio build.gradle add rely:

dependencies {
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:appcompat-v7:23.4.0'
  compile 'com.android.support:recyclerview-v7:23.3.0'
  compile 'com.google.code.gson:gson:2.2.4'
  compile 'org.greenrobot:eventbus:3.0.0'
  compile files('libs/minewDevice.jar')
  }
1
2
3
4
5
6
7
8

More details,refer demo code.

The MinewKeyFinder SDK provides three classes to obtain anti-lost information and management of the anti-lost device. MinewDeviceManager is the management of all devices. MinewDevice is the device instance class. MinewDeviceValue is the device information data class. Please refer to the corresponding section for details of each class. Be careful not to stop scanning, only when you determine all the devices has been connected to stop scanning. When the device is disconnected you must start scan, or can not be re-connected.

Get Started

Device manager

MinewDeviceManager(as Manager)is a shared instance Manager Class, it can scan / connect to / bind devices, at the same time, it also listen the changes of device connection.

1.init Manager, set a callback:

MinewDeviceManager manager = MinewDeviceManager.getInstance(this);
1

2.start scan, find devices around:

 manager.startScan();
     PS:If the user turns off the Bluetooth, you can listen to MinewDeviceManagerListener callback method to obtain the state change.
     
 manager.setMinewDeviceManagerListener(MinewDeviceManagerListener minewDeviceManagerListener);
	
 void onUpdateBluetoothState:(BluetoothState state){}   
1
2
3
4
5
6

the manager will create instances for every device when it scanned devices around, there are 3 methods call back for events and status.

// when the manager find devices, this method will be executed.
 void onScanDevices(List<MinewDevice> devices);

// when device disappear this method will be executed.(PS: if a device doesn't been scanned for 10 seconds, we think it "disappeared".)
 void onDisappearDevices(List<MinewDevice> devices);

// when device appear this method will be executed.(PS: only for the first scanned devices.)
 void onAppearDevices(List<MinewDevice> devices);
1
2
3
4
5
6
7
8

Certainly, the develop can get devices from the "scannedDevices" property of manager.

List<MinewDevice> allDevices = MinewDeviceManager.scannedDevices;
1

3.bind device:

The manger only update data of bind devices, especially in connection stage.you can bind a device like the code below:

manager.bind(minewDevice);
1

At same time, the developer can get all bind devices in this way:

List<MinewDevice> allBindDevices = MinewDeviceManager.bindDevices;
1

4.connect to a device:

Connect to device via manager, you can listen the status or event changes of device from delegate method.

manager.connect(minewDevice);
1

the methond will be executed when device connection state changes.

// the methond will be executed when device connection state changes.
- void onDeviceChangeStatus(MinewDevice device,DeviceLinkStatus status);
1
2

the manager update data of devices by delegate method, it's only for bind devices.

// when data changes of bind devices, this method will be executed.
 void onUpdateBindDevice:(List<MinewDevice> device);
1
2

Working switch

from ver2.1.1, the SDK has a switch, you can disable the SDK module for stoping manager's work.

private boolean disableAutoProcessing;
1

the default value of this property is false, if you need stop the SDK from working, just set it to true, this will take effect immediately.

the default value of this property is false, if you want stoping autoProccessing, just set it to true, it will take effective immediately. It is worth noting that you can't bind devices when disable autoProcessing(there is example code in Demo).

Device

This SDK create MinewDevice instance for every physical device, each instance contains information, operation methods and call backs for device.

Currently, you can get device information by key-value(like map). refer to the code below:

// get value instance of MAC,
MinewDeviceValue value = minewDevice.getValue(ValueIndex.ValueIndex_MacAddress);

// get MAC address string.
String macAddress = value.getStringValue;
1
2
3
4
5

You may notice that the " -minewDevice.getValue(ValueIndex.ValueIndex_MacAddress)" method will return a MinewValue (as value below) instance, value isntance is a package of mutilple types, such as int, float, string and etc. more detailed explanation later.

you can refer to the code below about change values of device.

// init a MinewValue instance.
MinewDeviceValue value = MinewDeviceValue.index(ValueIndex.ValueIndex_Connected, true);
1
2

if you want to change a bool / int / float type, please refer the code below:

//set the delay alarm property 
minewDevice.setValue(MinewDeviceValue.index(ValueIndex.ValueIndex_AlarmDelay, deleyValue));

// set alarm or not when disconnected.
minewDevice.setValue(MinewDeviceValue.index(ValueIndex.ValueIndex_DeviceLoseAlert, loseAlert));
1
2
3
4
5

we offer some instructions for control features of device. such as search device(the device will ring when receive the instruction)

minewDevice.sendInstruction(InstrucIndex_Search);	
1

When instructions sent, you can get the result by call backs.

// this callback tells the instruction is sent successful or not
 void onSendData(MinewDevice minewDevice, InstrucIndex index, boolean success);
1
2

At the same time, some events are passive, such as the device sends a instruction to app, but we don't know when it happens. we can listen these events like this:

// index is a item from "InstrucIndex" list
 void onReceiveInstructionfromDevice(InstrucIndex index, MinewDevice device);
1
2

OK, Start to develop now, we provided a demo code, you can encapsulate MinewDeviceManager and MinewDevice in order to accept every event callback accurately. More details, please refer to the demo.

Details about MinewDeviceValue

get values like this,

 device name:String name = aDeviceValue.stringValue
 battery:int battery = aDeviceValue.intValue;
 bind state:boolean bind = aDeviceValue.boolValue;

DeviceValue contains multiple types, you can refer to the code below.

// index in "ValueIndex" list
pirvate ValueIndex index;

// get int value
private int intValue;

// get float value
private float floatValue;

// get string value
private String stringValue;

// get byte[] value
private byte[] dataValue;

// get boolean value
private boolean boolValue;

If you want to change a value, please init a value instance.

 // init a value instance
 public <T> MinewDeviceValue index(ValueIndex index, T t){}

 // create a name instance
 MinewDeviceValue nameValue = MinewDeviceValue.index(ValueIndex_Name,"phone");
 
 // create a device mode instance
 MinewDeviceValue modeValue = MinewDeviceValue.index(ValueIndex_Mode,2);

At the same time, you should to known, not all the properties can be modified, please refer the table below:

Device Properties detail datatype Read/write More
ValueIndex_Name Name stringValue R/W
ValueIndex_HeadImage Head image dataValue R/W
ValueIndex_DeviceId Device id stringValue R Bluetooth name.
ValueIndex_MacAddress Mac address stringValue R
ValueIndex_Rssi Rssi intValue R
ValueIndex_Mode Mode intValue R/W
ValueIndex_Distance Distance floatValue R
ValueIndex_Battery Battery intValue R
ValueIndex_Bind Bind state boolValue R
ValueIndex_DisappearTime Disconnect time stringValue R Format:yyyy-MM-dd hh:mm:ss
ValueIndex_DisappearLong Disconnect longitude floatValue R
ValueIndex_DisappearLati Disconnect latitude floatValue R
ValueIndex_Connected Connection state boolValue R
ValueIndex_DeviceLoseAlert Device alert boolValue R/W device will alarm or not when disconnect.
ValueIndex_Search Search boolValue R/W searching this device or not.
ValueIndex_AppLoseAlert App Alert boolValue R/W app will alarm or not when disconnect.
ValueIndex_FeatureSupport feature support boolValue R If the device supports distance adjustment or delayed alarm adjustment, it's true.
ValueIndex_AlarmDistance Alarm distance intValue R/W 1 - 8, 8 levels, from near to far (when featuresupport is true)
ValueIndex_AlarmDelay Alarm delay. intValue R/W 0 - 8 seconds.(when featuresupport is true)

ChangeLog

2018.11.20

Fixed bug for scanning;

2017.04.26

update some text description;

2017.04.20

working switch;

2017.01.06

new feature and permission;

2016.09.12

first version;

Last Updated:: 11/20/2018, 11:58:04 AM