0
我一直在试图创建一个应用程序,它将显示有蓝牙功能的手机,当我在列表视图中点击其中一个时,它们会将它们配对。我仍然在学习蓝牙,所以我有点麻烦项目上的蓝牙双设备点击
我怎么能配对列表中显示的设备,当我点击它的列表视图?
如果有人决定downvote,请留下评论为什么我downvoted。预先感谢任何帮助或见解! :d
这是我的活动:
private BluetoothAdapter BA;
private BluetoothDevice device;
private Set<BluetoothDevice>pairedDevices;
private ArrayList list;
private ArrayAdapter adapter;
private ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BA = BluetoothAdapter.getDefaultAdapter();
lv = (ListView)findViewById(R.id.listViewPaired);
list = new ArrayList();
lv.setOnItemClickListener(this);
}
final BroadcastReceiver bReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)){
device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
adapter.add(device.getName() + "\n" + device.getAddress());
adapter.notifyDataSetChanged();
}
}
};
public void find(View v)
{
txtTitle.setText("SEARCHING NEW DEVICES");
adapter.clear();
if (BA.isDiscovering()) {
BA.cancelDiscovery();
}
else {
BA.startDiscovery();
registerReceiver(bReceiver, new IntentFilter(BluetoothDevice.ACTION_FOUND));
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String value = String.valueOf(list.get(position));
Toast.makeText(MainActivity.this, value , Toast.LENGTH_LONG).show();
}
}
问题是......? – Sergio
@Sergio对不起,先生,更新了我的问题。当它在列表视图中显示时,我怎么能够配对这两个设备。 –