代码拉取完成,页面将自动刷新
##讨论室
小米运动app:
普通版:(MI)
心率版(MI1S)
// 实例化
MiBand miband = new MiBand(context);
// 扫描附近的设备
final ScanCallback scanCallback = new ScanCallback()
{
@Override
public void onScanResult(int callbackType, ScanResult result)
{
BluetoothDevice device = result.getDevice();
Log.d(TAG,
“找到附近的蓝牙设备: name:” + device.getName() + “,uuid:”
+ device.getUuids() + “,add:”
+ device.getAddress() + “,type:”
+ device.getType() + “,bondState:”
+ device.getBondState() + “,rssi:” + result.getRssi());
// 根据情况展示
}
};
MiBand.startScan(scanCallback);
// 停止扫描
MiBand.stopScan(scanCallback);
// 连接, 指定刚才扫描到的设备中的一个
miband.connect(device, new ActionCallback() {
@Override
public void onSuccess(Object data)
{
Log.d(TAG,"connect success");
}
@Override
public void onFail(int errorCode, String msg)
{
Log.d(TAG,"connect fail, code:"+errorCode+",mgs:"+msg);
}
});
// 设置断开监听器, 方便在设备断开的时候进行重连或者别的处理
miband.setDisconnectedListener(new NotifyListener()
{
@Override
public void onNotify(byte[] data)
{
Log.d(TAG,
“连接断开!!!”);
}
});
// 设置心跳扫描结果通知
miband.setHeartRateScanListener(new HeartRateNotifyListener()
{
@Override
public void onNotify(int heartRate)
{
Log.d(TAG, "heart rate: "+ heartRate);
}
});
//开始心跳扫描
miband.startHeartRateScan();
// 读取和连接设备的信号强度Rssi值
miband.readRssi(new ActionCallback() {
@Override
public void onSuccess(Object data)
{
Log.d(TAG, "rssi:"+(int)data);
}
@Override
public void onFail(int errorCode, String msg)
{
Log.d(TAG, "readRssi fail");
}
});
// 读取手环电池信息
miband.getBatteryInfo(new ActionCallback() {
@Override
public void onSuccess(Object data)
{
BatteryInfo info = (BatteryInfo)data;
Log.d(TAG, info.toString());
//cycles:4,level:44,status:unknow,last:2015-04-15 03:37:55
}
@Override
public void onFail(int errorCode, String msg)
{
Log.d(TAG, "readRssi fail");
}
});
//震动2次, 三颗led亮
miband.startVibration(VibrationMode.VIBRATION_WITH_LED);
//震动2次, 没有led亮
miband.startVibration(VibrationMode.VIBRATION_WITHOUT_LED);
//震动10次, 中间led亮蓝色
miband.startVibration(VibrationMode.VIBRATION_10_TIMES_WITH_LED);
//停止震动, 震动时随时调用都可以停止
miband.stopVibration();
//获取普通通知, data一般len=1, 值为通知类型, 类型暂未收集
miband.setNormalNotifyListener(new NotifyListener() {
@Override
public void onNotify(byte[] data)
{
Log.d(TAG, "NormalNotifyListener:" + Arrays.toString(data));
}
});
// 获取实时步数通知, 设置好后, 摇晃手环(需要持续摇动10-20下才会触发), 会实时收到当天总步数通知
// 使用分两步:
// 1.设置监听器
miband.setRealtimeStepsNotifyListener(new RealtimeStepsNotifyListener() {
@Override
public void onNotify(int steps)
{
Log.d(TAG, "RealtimeStepsNotifyListener:" + steps);
}
});
// 2.开启通知
miband.enableRealtimeStepsNotify();
//关闭(暂停)实时步数通知, 再次开启只需要再次调用miband.enableRealtimeStepsNotify()即可
miband.disableRealtimeStepsNotify();
//设置led颜色, 橙, 蓝, 红, 绿
miband.setLedColor(LedColor.ORANGE);
miband.setLedColor(LedColor.BLUE);
miband.setLedColor(LedColor.RED);
miband.setLedColor(LedColor.GREEN);
// 获取重力感应器原始数据, 需要两步
// 1. 设置监听器
miband.setSensorDataNotifyListener(new NotifyListener()
{
@Override
public void onNotify(byte[] data)
{
int i = 0;
int index = (data[i++] & 0xFF) | (data[i++] & 0xFF) << 8; // 序号
int d1 = (data[i++] & 0xFF) | (data[i++] & 0xFF) << 8;
int d2 = (data[i++] & 0xFF) | (data[i++] & 0xFF) << 8;
int d3 = (data[i++] & 0xFF) | (data[i++] & 0xFF) << 8;
}
});
// 2. 开启
miband.enableSensorDataNotify();
// 设置UserInfo, 貌似没啥用, 不配对也可以做其他的操作
// 并且在手环闪动的时候, 需要拍一下手环; 就像官方app 配对时一样
UserInfo userInfo = new UserInfo(20111111, 1, 32, 180, 55, "胖梁", 1);
miband.setUserInfo(userInfo);
// 配对, 貌似没啥用, 不配对也可以做其他的操作
miband.pair(new ActionCallback() {
@Override
public void onSuccess(Object data)
{
changeStatus("pair succ");
}
@Override
public void onFail(int errorCode, String msg)
{
changeStatus("pair fail");
}
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。