Coder Social home page Coder Social logo

advertisersdk's Introduction

advertisersdk

一、简介及运行环境

概述
本文档是基于BLE蓝牙的Android SDK用户指南,描述了开启扫描、停止扫描、开始搜索指定设备、连接指定设备、发送广播数据、
停止发送广播数据等相关接口的使用说明。
兼容性
类别	兼容范围
系统	支持Android 5.0 以上版本 API LEVEL 21
机型	上市的android手机和平板。对其它android设备及订制系统不做官方支持
硬件要求	要求设备支持蓝牙BLE4.0
网络	无要求
开发环境	建议使用最新版本Android Studio 进行开发
DEMO压缩包说明

DEMO压缩包下载即可运行,其中DEMO内已经附带了SDK的库。

  • advertise_sdk.jar位于app/libs目录下
  • armeabi-v7a,arm64-v8a,x86,x86_64 app/src/main/jniLibs 目录下
  • jar和so库接入目录位置参考DEMO

二、接口使用及调用流程

提示:先检测蓝牙并打开蓝牙,并动态授权蓝牙相关权限(非SDK相关,具体参考DEMO)
1、初始化SDK
        AdvertiserClient
                .config()//开启配置
                .setThroAvertiseException(true)//是否抛出异常
                .setLogAvertise(true)//是否打印日志
                .setPrefixAvertiseName("MTT-")//扫描指定设备的前缀名
                .setScanPeriod(8 * 1000)//扫描周期(默认连接设备的超时时间相同)
                .create(getApplication());
2、扫描指定目标设备
 
3、连接指定目标设备

4、发送广播包数据

5、停止发送广播包

6、开启蓝牙扫描(APP和2.4G设备双向交互时,必须开启蓝牙扫描,否则APP收不到2.4G设备的回复)

三、自定义协议说明

如:
byte0 - byte15 为 K1 X1 X2 X3 C0 K2 K3 H1 H2 H3 H4 00 00 Y1 Y2 Y3
K1数据为随机数,00~255
K2数据为帧序号,只要确定用户按下app的按键或者松开,触发手机发送广播时数据就累加1,否则就继续保持当前值发送出去
X1 X2 X3为对码时收到的2.4G终端的滚码
Y1,Y2,Y3为2.4G在对码时刻收到的手机的码
C0 代表APP添加属性
H1~H4为记录属性状态:
H1为前进属性;H2为后退属性;H3为左转属性;H4为右转属性,对应的BYTE为00表示没有此功能,为01表示有此功能。
手机发送给硬件时:K3为0x01
硬件回复给手机时:K3为0x11 (手机收到此码后退出属性设置模式)

advertisersdk's People

Contributors

aicareles avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.