SeekcyBeacon SDK for Android 集成指南




● 产品功能说明


目前我们的 Android SDK,主要提供以下功能:

  1. 扫描周围的SeekcyBeacon

2. 连接、配置SeekcyBeacon

3. 区域监听SeekcyBeacon:进入、离开


● SDK集成


1. SeekcyBeacon_SKD_Android-master.zip集成压缩包内容


SeekcyBeaconSDKLibs:so库、jar

SeekcyBeaconSDKDemo:一个完整的Android项目,演示SeekcyBeacon SDK的基本用法,可以用作参考

Documents:SDK APISDK使用说明

README.md:版本更新信息

2.导入SDK开发包到工程

        解压缩SeekcyBeacon_SKD_Android-master.zip,复制SeekcyBeaconSDKLibs文件夹下的文件到工程的libs目录下

3. 配置AndroidManifest.xml


<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
       android:name="android.hardware.bluetooth_le"
android:required="true" />

<application>
       <service android:name="com.skybeacon.sdk.locate.BleScanService" />
       <service android:name="com.skybeacon.sdk.config.BluetoothLeService" />
</application>


● 使用代码示例


1. 扫描代码示例


(1) SeekcyBeacon防蹭用

/*
 * 设置SeekcyBeacon防蹭用密钥,若不是防蹭用iBeacon,可以不设置
 */
skyBeaconManager.setBroadcastKey("AB11221498756731BCD7D8E239E765AD52B7139DE87654DAB27394BCD7D792A");

注意:
请在SDK启动前设置;防蹭用密钥必须为32bytes长度的十六进制String类型,密钥由Seekcy提供,并且配合支持防蹭用的SeekcyBeacon使用。


(2)扫描示例

private static final SKYRegion ALL_SEEKCY_BEACONS_REGION = new SKYRegion("rid_all", null, null, null, null);
private SKYBeaconManager skyBeaconManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

skyBeaconManager = new SKYBeaconManager(this);
/**
* 设置SeekcyBeacon防蹭用密钥,若不是防蹭用iBeacon,可以不设置
*/
skyBeaconManager.setBroadcastKey("AB11221498756731BCD7D8E239E765AD52B7139DE87654DAB27394BCD7D792A");
skyBeaconManager.setRangingBeaconsListener(new RangingBeaconsListener() {
@Override
public void onRangedBeaconsMultiIDs(SKYRegion arg0, List<SKYBeaconMultiIDs> arg1) {
// TODO Auto-generated method stub
// 多id beacons扫描结果处理
}
@Override
public void onRangedBeacons(SKYRegion arg0, List<SKYBeacon> arg1) {
// TODO Auto-generated method stub
// 单id beacons扫描结果处理
}
});
}

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onStart();
startRanging();
}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onStop();
stopRanging();
}

private void startRanging() {
skyBeaconManager.startScanService(new ScanServiceStateCallback() {
@Override
public void onServiceDisconnected() {
// TODO Auto-generated method stub
}
@Override
public void onServiceConnected() {
// TODO Auto-generated method stub
skyBeaconManager.startRangingBeacons(ALL_SEEKCY_BEACONS_REGION);
}
});
}

private void stopRanging() {
if (skyBeaconManager != null) {
skyBeaconManager.stopScanService();
skyBeaconManager.stopRangingBeasons(ALL_SEEKCY_BEACONS_REGION);
}
}


2. 连接、配置示例代码


注意:建议连接Beacon前先调用skyBeaconManager.stopScanService()以及skyBeaconManager.stopRangingBeacons(Object)方法停止扫描

private SKYBeaconCommunication skyBeaconCommunication;
private SKYBeacon skyBeacon;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test1);

// 获取扫描到的需要配置的iBeacon
skyBeacon = (SKYBeacon) getIntent().getSerializableExtra("skyBeacon");
skyBeaconCommunication = new SKYBeaconCommunication(this);
}

ConnectionStateCallback connectionStateCallback = new ConnectionStateCallback() {
@Override
public void onDisconnected() {
// TODO Auto-generated method stub
}
@Override
public void onConnectedSuccess(SKYBeaconMultiIDs arg0) {
// TODO Auto-generated method stub
}
@Override
public void onConnectedSuccess(SKYBeacon arg0) {
// TODO Auto-generated method stub
// arg0为连接后获取的beacon详细信息
configBeacon();
}
@Override
public void onConnectedFailed(SKYBeaconConfigException arg0) {
// TODO Auto-generated method stub
}
};
private boolean configBeacon(){
boolean result = false;
SKYBeaconConfig skyBeaconConfig = new SKYBeaconConfig();
skyBeaconConfig.setProximityUUID("00000000-0000-0000-0000-000000000000");
skyBeaconConfig.setMajor(0);
skyBeaconConfig.setMinor(0);
result = skyBeaconCommunication.configSKYBeacon(skyBeaconConfig, new ConfigCallback() {
@Override
public void onConfigSuccess() {
// TODO Auto-generated method stub
}
@Override
public void onConfigFailed(SKYBeaconConfigException arg0) {
// TODO Auto-generated method stub
}
});
return result;
}

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
skyBeaconCommunication.connect(skyBeacon, connectionStateCallback);
}

@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
skyBeaconCommunication.disconnect();
}



3. 区域监听示例代码


private static final SKYRegion MONITOR_REGION_TEST = new SKYRegion("rid_test", null, "00000000-0000-0000-0000-000000000000", 0, 0);

private SKYBeaconManager skyBeaconManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test1);

skyBeaconManager = new SKYBeaconManager(this);
skyBeaconManager.setMonitoringBeaconsListener(monitoringBeaconsListener);
}

MonitoringBeaconsListener monitoringBeaconsListener = new MonitoringBeaconsListener() {
@Override
public void onExitedRegion(SKYRegion arg0, List<SKYBeacon> arg1) {
// TODO Auto-generated method stub
}
@Override
public void onEnteredRegion(SKYRegion arg0, List<SKYBeacon> arg1) {
// TODO Auto-generated method stub
}
};

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onStart();
startMonitoring();
}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onStop();
stopMonitoring();
}
private static final SKYRegion MONITOR_REGION_TEST = new SKYRegion("rid_test", null, "00000000-0000-0000-0000-000000000000", 0, 0);

private SKYBeaconManager skyBeaconManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test1);

skyBeaconManager = new SKYBeaconManager(this);
skyBeaconManager.setMonitoringBeaconsListener(monitoringBeaconsListener);
}

MonitoringBeaconsListener monitoringBeaconsListener = new MonitoringBeaconsListener() {
@Override
public void onExitedRegion(SKYRegion arg0, List<SKYBeacon> arg1) {
// TODO Auto-generated method stub
}
@Override
public void onEnteredRegion(SKYRegion arg0, List<SKYBeacon> arg1) {
// TODO Auto-generated method stub
}
};

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onStart();
startMonitoring();
}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onStop();
stopMonitoring();
}



● 总结

至此,您已完成SDK整合进您项目的全部工作。更多技术细节,请参考完整的SDK API文档,以及我们的示例工程