zoukankan      html  css  js  c++  java
  • android ble 蓝牙4.0开发日志(四)

    要拿到蓝牙信号指示值 rssi 分为两个步骤。
    1.在oncreate方法里面增加 注册扫描广播

    public void onCreate(Bundle savedInstanceState) {                                       // 注册开始发现广播。                              IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);                              this.registerReceiver(mReceiver, filter);                                            }

    2.新建BroadcastReceiver广播对象,并实现里面的onreceive方法,在onreceive得到rssi(信号强度)。

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {                 @Override                 public void onReceive(Context context, Intent intent) {                         String action = intent.getAction();                           //当设备开始扫描时。                         if (BluetoothDevice.ACTION_FOUND.equals(action)) {                                 //从Intent得到blueDevice对象                                 BluetoothDevice device = intent                                                 .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);                                                                   if (device.getBondState() != BluetoothDevice.BOND_BONDED) {                                           //信号强度。                                         short rssi = intent.getExtras().getShort(                                                         BluetoothDevice.EXTRA_RSSI);                                                                                   }                                                           }                 }         };
  • 相关阅读:
    接口调试之Postman 使用方法详解
    用Vue2仿京东省市区三级联动效果
    高德地图JS API获取经纬度,根据经纬度获取城市
    js 格式化数字,格式化金额:
    CSS Media媒体查询使用大全,完整媒体查询总结
    最新手机号正则表达式 java 、javascript版正则表达式验证是否为11位有效手机号码
    JavaScript 实现textarea限制输入字数, 输入框字数实时统计更新,输入框实时字数计算移动端bug解决
    在上线项目中,用Vue写一个星级评价
    new Date()设置日期在IOS的兼容问题
    javascript 省市区三级联动 附: json数据
  • 原文地址:https://www.cnblogs.com/luwenbin/p/3118918.html
Copyright © 2011-2022 走看看