yunlinBleLocklib 使用说明

引入工程方式

  1. clone yunlinBleLockLib 库到项目中
  git clone    yunlinBleLockLib(url)
  1. gradle 中增加依赖库
 implementation project(':yunlinBleLockLib') 

或者

   compile project(':yunlinBleLockLib') 

项目集成蓝牙锁操作步骤说明

关于动态权限

  1. 申请权限 (扫描设备要申请 蓝牙扫描设备权限)
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
//请求权限
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
                                              REQUEST_BLUTOOTH_CODE);
//判断是否需要 向用户解释,为什么要申请该权限
            if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                                                                    Manifest.permission.READ_CONTACTS)) {
                Toast.makeText(this, "shouldShowRequestPermissionRationale", Toast.LENGTH_SHORT).show();
            }
            return;
        }
  1. 申请权限结果处理
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[]
            grantResults){
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        
        switch (requestCode) {
            case REQUEST_BLUTOOTH_CODE:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    //用户同意授权
                    setScaningStatuAndexecuteScan();
                }else {
                    //用户拒绝授权
                }
                break;
        }
    }

开锁步骤操作说明

  1. bleControler 初始化(参考Demo使用说明)
bleController=new BleController(MainActivity.this, new IBteScanConnectListner(){  
          @Override
          public void onScanResult(final List scanedDevices){
          //扫描结果 (放入list  通知页面 数据)
          }
          
          @Override
          public void onReiceveBleDeviceDat(OpenLockStatus openLockStatus){
            //开锁结果页面 封装 开锁成功、失败、耗时
          }
          
          
          @Override
          public void onBleConnect(){
            //锁 连接上 回调
          }
          
          @Override
          public void onBleBusy(){
            //锁 忙碌回调
          }
          
          @Override
          public void onOtheDeviceIsConnecting(){
           //其他设备正在连接回调。不支持多个设备同时连接
          }
          
          //连接断开
          @Override
          public void onBleDisConnect(){
            //锁 断开链接回调
          }
          
          @Override
          public void needReScan(){
          // 锁 忙碌、无响应、重新扫描回调
          }
      });
      bleController.init(); //执行Init
  1. 执行扫描蓝牙设备
    @Override
    protected void onResume(){
        super.onResume();
        bleController.scanBteLockDevice();
  
    }
    

说明: 扫描结果在 bleControler回调中,连接状态、开锁状态、获取设备状态都在,请在bleController中拿到蓝牙锁扫描结果。

  1. 开锁操作(参考Demo 点击item 或点击开锁按钮执行开锁)
    备注: 是连接成功后,自动开锁
bleController.connectDevice(bleDevices.get(position), false);
  1. bleController销毁与释放连接
   @Override
    protected void onDestroy(){
        super.onDestroy();
        bleController.releaseConnect(false);
    }

BleController模式说明

操作锁的模式,即点击item执行的操作动作

FUNCTION_OPEN_LOCK    //开锁
FUNCTION_READ_BATTERY_INFO //获取锁电量、音量、电压
FUNCTION_VERIFY_ADMIN=11;//认证锁设备
  1. 默认模式 (默认点击Item执行开锁 参考Demo)
BleController.FUNCTION_OPEN_LOCK
  1. 设备状态 模式 (点击获取设备 切换到 获取设备状态模式)
 bleController.setCurrentFunctionMode(BleController.FUNCTION_VERIFY_ADMIN);
  1. 管理员认证模式(点击管理员认证切换到管理员认证模式)
 bleController.setCurrentFunctionMode(BleController.FUNCTION_OPEN_LOCK);

你可能感兴趣的:(yunlinBleLocklib 使用说明)