Lavichord 2016-12-30 04:59 采纳率: 0%
浏览 1874
已结题

Android蓝牙怎么获取“可用用户”的RSSI?

两部手机开启蓝牙,只“搜索”而不“匹配”,可以获得RSSI吗?
我试过官方demo,但是根本搜索不到任何手机(两部手机是没问题的,可以匹配的到),也搜不到粗粮手环。
我想获取RSSI来计算大概距离。

另外下面这些网上搜到的代码我试过了也没用

/*------------------------------------------------------------------------------*/

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

                // 注册开始发现广播。 
                         IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED); 
                         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); 

                            } 

                    }  
            } 
    }; 
  • 写回答

1条回答 默认 最新

  • devmiao 2016-12-30 17:04
    关注
    评论

报告相同问题?

悬赏问题

  • ¥20 5037端口被adb自己占了
  • ¥15 Error in check.length("fill") : 'gpar'成分'fill'的长度不能为零
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误