【发布时间】:2014-03-06 08:32:53
【问题描述】:
我列出了所有配对的设备,它运行良好,但现在想获取配对设备的蓝牙信号强度...我知道它将通过使用 rssi 获得,但无法在我的应用程序中连续获取它.. 请给我合适的代码作为我的代码...我的代码在这里...
public class Security extends Fragment implements OnClickListener{
private BluetoothAdapter BA;
private Set<BluetoothDevice>pairedDevices;
ArrayList<String> mylist = new ArrayList<String>();
//private Object ImageView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.security, null);
BA = BluetoothAdapter.getDefaultAdapter();
/* starting the bluetooth*/
on(v);
pairedDevices = BA.getBondedDevices();
//length=4;
// int j=1;
for(BluetoothDevice bt : pairedDevices) {
mylist.add(bt.getName());
length=j;
j++;
bt.getBondState();
}
return v;
}
@Override
public void onResume() {
super.onResume();
// Toast.makeText(getActivity(), "On resume", Toast.LENGTH_LONG).show();
}
/*************************Bluetooth function****************************/
public void on(View view){
if (!BA.isEnabled()) {
Intent turnOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(turnOn, 0);
Toast.makeText(getActivity(),"Turned on"
,Toast.LENGTH_LONG).show();
} else{
// Toast.makeText(getActivity(),"Already on",
// Toast.LENGTH_LONG).show();
}
}
public void Discovery(View view) {
if(BA.isDiscovering()) {
BA.cancelDiscovery();
}
}
public void list(View view){
Toast.makeText(getActivity(),"Showing Paired Devices",
Toast.LENGTH_SHORT).show();
}
@Override
public void onClick(View v) {
for(int j=0;j<length;j++) {
if(v.getId()==j)
Toast.makeText(getActivity(), mylist.get(j), Toast.LENGTH_LONG).show();
//hand.update(run,1000);
}
}
}
【问题讨论】:
-
您只需要配对设备吗?因为您没有发现蓝牙设备。
-
是的,只有活动的配对设备...
-
如果您正在考虑使用活动设备,那么它将已经与您的设备配对。
-
一切正常,但我无法连续获取活动配对设备的 rssi ......
-
嗨 Dhiman,您有解决方案吗?我面临同样的问题。请帮帮我。