• 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);                                                                                   }                                                           }                 }         };
  • 相关阅读:
    国内的maven镜像
    Python Flask UnicodeDecodeError 编码错误解决
    关于Python的web框架
    SDL2+OpenGL (4)混合图像产生动态效果
    什么是OpenGL中的深度、深度缓存、深度测试?
    SDL2+OpenGL (3)纹理映射
    SDL2+OpenGL (2)绘制立体图形
    SDL2+OpenGL (1)绘制多边形
    SDL2中使用OpenGL绘图
    CodeBlocks16.01 MinGW32位 配置SDL2.0.4
  • 原文地址:https://www.cnblogs.com/luwenbin/p/3118918.html
Copyright © 2020-2023  润新知