获取蓝牙信号强度 [英] Get bluetooth signal strength

查看:961
本文介绍了获取蓝牙信号强度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得它连接到我的手机另一个设备的蓝牙信号强度,

i want to get the bluetooth signal strength of a another device which connected to my phone,

我怎样才能蓝牙信号强度?

how can i get the bluetooth signal strength?

我试图寻找了很多对谷歌,并没有找到任何答案。

i tried to search alot over google and didnt find any answer.

也有人知道我怎么能实现呢?

do someone know how can i implement it?

非常感谢

这是myActivity:

this is myActivity:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_FOUND));


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    private final BroadcastReceiver receiver = new BroadcastReceiver(){
        @Override
        public void onReceive(Context context, Intent intent) {

            String action = intent.getAction();
            if(BluetoothDevice.ACTION_FOUND.equals(action)) {
                int rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE);
                Toast.makeText(getApplicationContext(),"  RSSI: " + rssi + "dBm", Toast.LENGTH_SHORT).show();
            }
        }
    };

}

和我也有一个蓝牙的权限在我的清单文件

and i also has a bluetooth permission in my manifest file

推荐答案

为了让您可以检查蓝牙RSSI信号,可以读取RSSI连接的设备,或执行一个蓝牙发现,检查RSSI的附近任何设备。

To get the signal you can check bluetooth RSSI, you can read RSSI for connected devices, or perform a bluetooth discovery to check the RSSI for any nearby devices.

基本上是一个蓝牙的发现是一个广播范围内的所有站来响应。由于每个设备respons回来了,Android的触发了一个ACTION_FOUND意图。在此意向,你可以getExtra EXTRA_RSSI获得RSSI。

Basically a bluetooth discovery is a broadcast to all stations within range to respond back. As each devices respons back, Android fires off an ACTION_FOUND intent. Within this intent you can getExtra EXTRA_RSSI to obtain the RSSI.

请注意,并非所有的蓝牙硬件支持RSSI。

Note that not all bluetooth hardware supports RSSI.

也有关系:<一href="http://stackoverflow.com/questions/2149776/android-irc-office-hours-question-about-android-bluetooth-rssi">Android IRC办公时间问题关于Android的蓝牙RSSI 我这里是

private final BroadcastReceiver receiver = new BroadcastReceiver(){
    @Override
    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();
        if(BluetoothDevice.ACTION_FOUND.equals(action)) {
            int  rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,Short.MIN_VALUE);
            Toast.makeText(getApplicationContext(),"  RSSI: " + rssi + "dBm", Toast.LENGTH_SHORT).show();
        }
    }
};

这篇关于获取蓝牙信号强度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆