我想获得它连接到我的手机另一个设备的蓝牙信号强度,
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.
也有关系: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();
}
}
};