【发布时间】:2013-03-09 16:11:17
【问题描述】:
我想获取连接到我手机的另一台设备的蓝牙信号强度,
如何获取蓝牙信号强度?
我在谷歌上搜索了很多,但没有找到任何答案。
有人知道我该如何实现它吗?
这是我的活动:
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();
}
}
};
}
我的清单文件中还有蓝牙权限。
【问题讨论】:
-
我已经看过了,但是没有任何关于如何找到信号强度的例子。也许你能帮我吗?
-
我认为您的代码还可以。要查看 Toast,您需要先执行 Discover。