a.兼容Android14
implementation 'com.blankj:utilcodex:1.31.1'
implementation 'androidx.work:work-runtime:2.7.1'
public class MyApplication extends Application {
@Override
public void onCreate() {
FitProSDK.getFitProSDK()
.setConfig(new Config()
.setNotificationImportance(NotificationUtils.IMPORTANCE_DEFAULT)//设置前台消息通知级别
.setNotificationTitle("你自己的标题")
.setNotificationContent("您自己的通知内容")
.setLogListener((tag, content) -> {//监听SDK返回的log信息,tag是用于定位日志页面的标记,content是log信息
Log.i(tag, content);//SDK log information
}))
.init(this);
}
}
/**
* 连接状态
*
* @return true = 已连接
*/
public static boolean isConnected();
/**
* 找手表
*
* @return 发送状态
*/
public static boolean findWatch();
/**
* 获取设备设置信息
*
* @return
*/
public static boolean getDeviceInfo();
/**
* 设置语言
*
* @return
*/
public static boolean setLanguage(int enable);
/**
* 解除绑定
*
* @return
*/
public static boolean unbondWatch();
/**
* 重置手环
*
* @return
*/
public static boolean resetWatch();
/**
* 获取目标步数
*
* @return
*/
public static boolean getTargetSteps();
/**
* 获取闹钟
*
* @return
*/
public static boolean getAlarms();
/**
* 设置闹钟
*
* @param alarms
*/
public static boolean setAlarms(byte[] alarms);
/**
* 获取测试数据
*/
public static boolean getTestData();
/**
* 关闭测试数据
*/
public static boolean closeTestData();
/**
* 自定义命令
*
* @param val
*/
public static boolean sendCustomOrder(byte[] val) ;
/**
* 设置抬腕亮屏
*
* @param data
*/
public static boolean setHandLight(byte[] data);
/**
* 获取翻腕亮屏信息
*/
public static boolean GetInfoOfWrist();
/**
* 开启拍照功能
*/
public static boolean openCamera();
/**
* 关闭拍照功能
*/
public static boolean closeCamera();
/**
* 设置务扰模式
*
* @param longSit
*/
public static boolean setDistuMode(byte[] data);
/**
* 获取勿扰模式信息
*/
public static boolean getDistuModeInfo();
/**
* 设置心率自动测量
*
* @param longSit
*/
public static boolean setHeartRateAutoMeas(byte[] data);
/**
* 获取心率自动测量信息
*/
public static boolean getHearRateAutoMeInfo();
/**
* 获取久坐提醒
*/
public static boolean getLongSitWarnInfo();
/**
* 开始测量心率
*/
public static boolean startMeasureHeatRate();
/**
* 获取个人信息
*
* @param data
*/
public static boolean getMessagesInfo(byte[] data);
/**
* 设置睡眠开关
*/
public static boolean switchSleep();
/**
* 获取睡眠开关信息
*/
public static boolean getSleepSwitchInfo();
/**
* app请求获取天总步数实时数据
*/
public static boolean getTotalSportData();
/**
* 获取个人信息
*/
public static boolean getPersonalInfo();
/**
* 应用程序根目录
*/
public static String RootPath = "";
/**
* 蓝牙服务通道对象
*/
public static LeService mService = null;
/**
* 媒体播放器
*/
public static MediaPlayer mediaPlayer = null;;
public static boolean isdialog = false;
/**
* 蓝牙连接状态 -2设备不支持蓝牙, -1蓝牙未打开, 0未连接, 1 已连接,3 连接失败
*/
public static int BleState = 0;
public static boolean hearting = false,blooding = false;//是否正在测试心率,血压
public static boolean isDeubg = true;
/**
* app是否在前台 0否, 1 是
*/
public static int IsAppOnForeground = 0;
/**
* 全局Handler
*/
public static Handler mHandler = null;
/**
* 升级状态
*/
public static int otaState = 0;//0 无,1 进入升级,2 DUF
/**
* 是否执行命令
*/
public static boolean isExecute = true;
/**
* 是否展示获取数据loading
*/
public static boolean isGetDataLoading = false;
/**
* 等待时间
*/
public static int waiting = 0;
SDKTools.mService.connect2(addr);
public static final int what1 = 1; // 发现蓝牙
public static final int what10 = 10; // 解绑手环
public static final int what11 = 11; // 接收历史数据中
public static final int what12 = 12; // 接收历史数据完成
public static final int what13 = 13; // 重置
public static final int what14 = 14; // 请求设置信息(取代 0x09 命令,具体 key 参考后面)
public static final int what2 = 2; // 蓝牙状态
public static final int what30 = 30; // 蓝牙初始设置显示 时间
public static final int what31 = 31; // 蓝牙初始设置显示 个人信息
public static final int what32 = 32; // 蓝牙初始设置显示 目标步数
public static final int what33 = 33; //设置消息推送开关(来电、短信、微信、QQ)
public static final int what34 = 34; //闹铃列表
public static final int what35 = 35; //设置闹铃
public static final int what36 = 36; //设置久坐提醒
public static final int what37 = 37; // 安卓手机来电推送(来电、挂断电话、电话号码和姓名)安卓手机消息推销(来电、短信、微信、QQ)
public static final int what38 = 38; //语言设置(value:中文:0x00 英文:0x01)
public static final int what39 = 39; //抬腕亮屏设置
public static final int what300 = 300; //勿扰模式
public static final int what301 = 301; //睡眠开关设置和睡眠有效时间段设置
public static final int what302 = 302; //心率自动测量
public static final int what4 = 4; // 蓝牙电量
public static final int what40 = 40; //左右手设置
public static final int what5 = 5; // 蓝牙运动实时步数
public static final int what51 = 51; //蓝牙运动数据15分钟返回一次
public static final int what60 = 60; //测量心率返回值
public static final int what61 = 61; //测量心率退出(手环主动发起)
public static final int what62 = 62; //测量血压返回值
public static final int what63 = 63; //测量血压退出(手环主动发起)
public static final int what64 = 64; //测量心率开始/关闭(APP发起)
public static final int what65 = 65; //测量血压开始/关闭(APP发起)
public static final int what70 = 70; //拍照
public static final int what71 = 71; //退出拍照
public static final int what72 = 72; //打开拍照
public static final int what80 = 80; //查找手机
public static final int what90 = 90; //睡眠数据返回
BleManager.getInstance().scanLeDevice(true)表示扫描设备
BleManager.getInstance().scanLeDevice(false)表示停止扫描设备
LeReceiver是SDK广播,可以监听所有SDK返回的数据,具体使用请参考示例代码MiBandReaderActivity.java
另外,Android 7 到Android11 需要打开定位并获取定位权限才能扫描到设备。
Android12及以上需要动态申请Manifest.permission.BLUETOOTH_CONNECT, Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_ADVERTISE权限
SDKCmdMannager 封装了常用的指令发送接口,直接调用就可以。
调用SDKTools.mService.commandPoolWrite可以发送自定义指令。例如
SDKTools.mService.commandPoolWrite(new byte[]{0,0,1}, "测试用例");
需要注册LeReceiver广播才能接收到设备的相关数据,具体示例代码请参考Demo中的MyApplication.java,里面有各种数据的接收示例.
说明:这个类是Android自身的广播,请按照普通广播的方式进行注册和取消注册
DEMO里Utils->weather->WeatherProxy是天气的业务代理实现。天气需要客户请求自己的天气接口,
并按照WeatherProxy的示例发送天气数据。
DEMO示例位于BluetoothCommandActivity页面
协议支持多天气和单个天气。
FitProSpUtils.isSupport3DaysWeather()表示true支持多天气
FitProSpUtils.isSupportWeather()表示true支持一天的天气
消息通知拦截在NotifyService.java有实现
默认SDK刚连上会同步手机本地语言到设备端。如果开发者需要根据自己的情况同步语言到设备端,请调用SDKCmdMannager.setLanguage(lang).
lang对应国家的编码:
中文:0x00 英文:0x01 繁体:0x02 阿拉伯语:0x03 捷克语:0x04 德语:0x05 西班牙语:0x06 法语:0x07 日语:0x08 马来西亚语:0x09 荷兰语:0xA 波兰语:0xB 葡萄牙语:0xC 俄语:0xD 斯洛伐克语:0xE 泰语:0xF 土耳其语:0x10 越南语:0x11 意大利语:0x12 菲律宾语:0x13 印尼语:0x14
乌克兰语:0x15 印度语:0x16 芬兰语:0x17 克罗地亚语:0x18 挪威语:0x19 丹麦语:0x1A 瑞典语:0x1B 韩语:0x1C 匈牙利语:0x1D 希腊语:0x1E 波斯语:0x1F 罗马尼亚语:0x20
public static final int ERROR_WAIT_TIMEOUT = 1001;//等待设备返回数据超时
public static final int ERROR_RESEND_TIMEOUT = 1002;//重发等待设备返回数据超时
public static final int ERROR_CHECK = 1003;//校验错误,设备端返回的
public static final int ERROR_IMG_FILE_NO_EXIST = 1004;//图片固件文件不存在
public static final int ERROR_FONT_FILE_NO_EXIST = 1005;//字体固件文件不存在
public static final int ERROR_BLE_DISCONNECTED = 1006;//app和设备已断开
public static final int ERROR_UNKNOWN = 1007;//未知错误,设备端返回0过来导致的
public static final int ERROR_BATTERY_LOW = 1008;//电量低
public static final int ERROR_CHARGE_BATTERY = 1009;//正在充电
com.legend.bluetooth.fitprolib.utils.NotificationUtil.startServiceNotification(title,content);
title是通知标题,content是通知内容。开发人员可以通过这个方法修改通知里面的内容。
ProfilePlus.what1 //表盘信息获取
ProfilePlus.what2 //设备信息返回
ProfilePlus.what3 //产品信息返回
Integer gender = FitProSpUtils.getGender();//获取性别,1表示男,0表示女,默认1
Integer age = FitProSpUtils.getAge();//获取年龄,默认25岁
Integer height = FitProSpUtils.getHeight();//获取身高,默认170cm
Integer weight = FitProSpUtils.getWeight();//获取体重,默认65kg
Integer weight = FitProSpUtils.getTargetSteps();//获取目标步数,默认5000
FitProSpUtils.setGender(gender);//设置性别,gender 1表示男性,0表示女性
FitProSpUtils.setAge(age);//设置年龄,age > 0
FitProSpUtils.setHeight(height);//设置身高 单位cm
FitProSpUtils.setWeight(weight);//设置体重 单位kg
FitProSpUtils.setTargetSteps(targetSteps);//设置目标步数,单位步,不设置默认5000
说明:这个类是缓存临时数据使用的,是基于SharedPreferences的封装
putStringValues(String key,String values)//存入String类型的值
getStringValues(String key,String defValue)//取出String类型的值
putIntValues(String key,int values) //存入int类型的值
getIntValues(String key,int defValue)//取出int类型的值
putLongValues(String key,long values)//存入long类型的值
getLongValues(String key,long defValue)//取出long类型的值
putFloatValues(String key,long values)//存入long类型的值
getFloatValues(String key,long defValue)//取出long类型的值
deleteAllValues()//删所有数据
removeKeyForValues(String key)//删除指定key
/**
* 获取性别
*
* @return 1表示男性,0表示女性
*/
public static int getGender();
/**
* 设置性别
*
* @param gender 1表示男性,0表示女性
*/
public static void setGender(int gender);
/**
* 设置年龄
*
* @param age
*/
public static void setAge(int age);
/**
* 获取年龄
*
* @return
*/
public static int getAge();
/**
* 设置身高
*
* @param height 单位cm
*/
public static void setHeight(int height);
/**
* 获取身高 单位cm
*/
public static int getHeight();
/**
* 设置体重 单位 kg
*/
public static void setWeight(int weight);
/**
* 获取体重
*
* @return 单位 kg
*/
public static int getWeight();
/**
* 获取目标步数
*/
public static int getTargetSteps();
/**
* 设置目标步数
*
* @param targetSteps
*/
public static void setTargetSteps(int targetSteps);
/**
* 设置目标睡眠
*
* @param targetSleep 单位小时
*/
public static void setTargetSleep(int targetSleep);
/**
* 获取目标睡眠
*
* @return 睡眠时长,单位小时
*/
public static int getTargetSleep();
/**
* 设置距离单位 (1->KM, 2->MILES)
*/
public static void setDistanceUnit(int distanceUnit);
/**
* 获取距离单位
*
* @return 距离单位(1 - > KM, 2 - > MILES)
*/
public static int getDistanceUnit();
/**
* @return 体重单位(1 - > KG. 2 - > 磅)
*/
public static int getWeightUnit();
/**
* 设置体重单位
*
* @param weightUnit 体重单位(1->KG. 2->磅)
*/
public static void setWeightUnit(int weightUnit);
/**
* @return 身高单位(1 - > CM, 2 - > 英寸)
*/
public static int getHeightUnit();
/**
* 设置身高单位
*
* @param heightUnit 身高单位(1->CM,2->英寸)
*/
public static void setHeightUnit(int heightUnit);
/**
* 设置温度单位
*
* @param tempUnit 温度单位(0->℃,1->℉)
*/
public static void setTemptUnit(int tempUnit);
/**
* 获取温度单位
*/
public static int getTemptUnit();
/**
* 获取mac地址
*
* @return
*/
public static String getBluetoothAddress();
/**
* 设置蓝牙mac地址
*
* @param bluetoothAddress
*/
public static void setBluetoothAddress(String bluetoothAddress);
/**
* 保存实时步数
* @param dist 距离
* @param realSteps 实时步数
* @param cal 卡路里 大卡
*/
public static void saveRealStepsInfo(int dist, int realSteps, int cal);
/**
* 获取实时步数
*
* @return 实时步数
*/
public static int getRealSteps();
/**
* 获取卡路里
*
* @return
*/
public static int getRealCal();
/**
* 获取实时距离
*
* @return 单位 m
*/
public static String getRealDistance();
/**
* 是否支持心率
*
* @return true 支持心率
*/
public static boolean isSurpportHeart();
/**
* 是否支持血压
* 利用的是运动位来判断是否支持睡眠,这个标记位没用到
*
* @return true 表示支持
*/
public static boolean isSurpportSleep();
/**
* 是否支持距离公英制转换
*
* @return true 表示支持
*/
public static boolean isSurpportDistance() ;
/**
* 是否支持微信运动
*
* @return true 表示支持
*/
public static boolean isSurpportWXSport();
/**
* 支持语音通话
*
* @return true 表示支持
*/
public static boolean isSurpportVoice();
/**
* 更新语音提示状态,true表示显示过
*/
public static void updateVoiceTipsStatus();
/**
* 是否显示过语音提示
*
* @return
*/
public static boolean isShownVoiceTips() ;
/**
* 默认支持来电提醒功能
*
* @return
*/
public static boolean isDefalutOpenCall();
/**
* 支持同步通讯录
*
* @return
*/
public static boolean isSupportSycContract();
/**
* 是否支持表盘设置
*
* @return
*/
public static boolean isSupportClockDialSettings() ;
/**
* 是否支持温度显示
*
* @return
*/
public static boolean isSupportTemp() ;
/**
* 是否支持天气
*
* @return
*/
public static boolean isSupportWeather() ;
/**
* 支持多天气
*
* @return
*/
public static boolean isSupport3DaysWeather();
/**
* 是否支持更多消息通知
*
* @return
*/
public static boolean isSupportMoreNotifi();
/**
* 是否支持更多消息通知
*
* @return
*/
public static boolean isShowAdv();
/**
* 是否支持远程拍照
*
* @return
*/
public static boolean isSupportRemoteCamera() ;
/**
* 是否支持找手环
*
* @return
*/
public static boolean isSupportFindDevice() ;
/**
* 是否支持心电
*
* @return
*/
public static boolean isSupportHREL() ;
/**
* 是否显示久坐时长
*
* @return
*/
public static boolean isShowLongSitTime() ;
/**
* 是否显示勿扰模式
*
* @return
*/
public static boolean isShowDisturnMode();
/**
* 是否显示二维码支付
*
* @return
*/
public static boolean isShowPay() ;
/**
* 是否支持来电语音播报功能
* @return false不支持,只发送名字或者电话号码。
* @return true 支持,需要发送名字和号码过去,名字在前,通过"/"进行分割
*/
public static boolean isSurpportVoicePlay() ;
/**
* 是否支持hid
* @return
*/
public static boolean isSurpportHid() ;
/**
* 公司有比较多的方案商,
* 为了适配不同的方案商并兼容以前的方案商区别处理
*/
public static boolean isManufacturer01();
public static boolean isManufacturer01(String macAddress);
/**
* 保存经典蓝牙地址
*/
public static void saveClassicMac(String addresss) ;
/**
* 经典蓝牙名称编码
*
* @param code
*/
public static void saveClassicBleNameCode(int code) ;
/**
* 获取 经典蓝牙名称编码
* @return 0x00:"LH728-Audio";0x01:"WellAudio";0x02:"LH722-Audio";0x03:AQFiT"
*/
public static int getClassicBleNameCode();
/**
* @param type 默认是0,1表示泰凌微平台,2表示LR平台,3表示BK平台,4表示OM平台
* @return
*/
public static void setPlarmType(int type;
/**
* 获取平台信息
* @return 默认是0,1表示泰凌微平台,2表示LR平台,3表示BK平台,4表示OM平台
*/
public static int getPlarmType() ;
/**
* 获取不会被解绑后清除的蓝牙mac地址
*
* @return
*/
public static String getLongCacheBleMac();
/**
* 缓存因为解绑后的蓝牙地址
*
* @param address
*/
public static void setLongCacheBleMac(String address) ;
/**
* 缓存蓝牙名称
*/
public static void cacheBluetoothName(String key, String bluetoothName) ;
/**
* 获取缓存蓝牙
*
* @param key
* @return
*/
public static String getCacheBluetoothName(String key);
/**
* 保存目标运动时间
* @param targetTime
*/
public static void saveTargetSportTime(short targetTime) ;
/**
* 保存经典蓝牙名称
* @param name
*/
public static void saveClassicBluetoothName(String name) ;
/**
* 获取目标运动时间
* @return
*/
public static int getTargetSportTime();
/**
* 是否支持震动模式
* @return true表示支持
*/
public static boolean isSupportShakeMode() ;
/**
* 是否支持联系人SOS
* @return true表示支持
*/
public static boolean isSupportSOSContract() ;
/**
* 是否支持抬手亮屏
* @return true表示支持
*/
public static boolean isSupportHandLight() ;
/**
* 获取经典蓝牙名
* @return
*/
public static String getClassicBluetoothName() ;
-keep class com.legend.bluetooth.fitprolib.model.** { *;}