Android 蓝牙测距离,两部蓝牙手机距离
答案:1 悬赏:40
解决时间 2021-01-08 11:54
- 提问者网友:愿为果
- 2021-01-08 04:28
Android 蓝牙测距离,两部蓝牙手机距离
最佳答案
- 二级知识专家网友:往事隔山水
- 2021-01-08 04:46
public class RssiUtil {
//A和n的值,需要根据实际环境进行检测得出
private static final double A_Value=50;
private static final double n_Value=2.5;
public static double getDistance(int rssi){
int iRssi = Math.abs(rssi);
double power = (iRssi-A_Value)/(10*n_Value);
return Math.pow(10,power);
}
}
扫描蓝牙过程中获得信号强度:
[java] view plain copy
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action))
{
// Get the BluetoothDevice object from the Intent
// 通过EXTRA_DEVICE附加域来得到一个BluetoothDevice设备
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// If it's already paired, skip it, because it's been listed already
// 如果这个设备是不曾配对过的,添加到list列表
//信号强度
int rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE);
追问这段代码我也试用过,可以跑起来BroadcastReceiver 没有调用到。
请把AndroidManifest,和layout也附上吧。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯