我有两个设备,其中包含用于蓝牙连接的自定义应用。
但是当我点击要配对的设备时,请显示以下消息:
我想要这样的确认针:
我使用此代码:
//----------------------------I set the devices in a list--------------------------------------------------------------------
private void getPairedDevices() {
Set<BluetoothDevice> pairedDevice = bluetoothAdapter.getBondedDevices();
if(pairedDevice.size()>0)
{
for(BluetoothDevice device : pairedDevice)
{
arrayListpaired.add(device.getName()+"\n"+device.getAddress()+ "\n DescContents: " + device.describeContents()
+ "\n BondState: " + device.getBondState()
+ "\n HashCode: " + device.hashCode()
+ "\n toString: " + device.toString()
+ "\n Class: " + device.getClass()
+ "\n Uuids: " + device.getUuids()
+ "\n BTClass: " + device.getBluetoothClass()
+ "\n "
);
arrayListPairedBluetoothDevices.add(device);
}
}
adapter.notifyDataSetChanged();
}
class ListItemClicked implements OnItemClickListener
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
bdDevice = arrayListBluetoothDevices.get(position);
//bdClass = arrayListBluetoothDevices.get(position);
Log.i("Log", "The dvice : "+bdDevice.toString());
connect(bdDevice);
Boolean isBonded = false;
try {
isBonded = createBond(bdDevice);
if(isBonded)
{
getPairedDevices();
adapter.notifyDataSetChanged();
}
} catch (Exception e) {
e.printStackTrace();
}
Log.i("Log", "The bond is created: "+isBonded);
}
}
private Boolean connect(BluetoothDevice bdDevice) {
Boolean bool = false;
try {
Log.i("Log", "service method is called ");
Class cl = Class.forName("android.bluetooth.BluetoothDevice");
Class[] par = {};
Method method = cl.getMethod("createBond", par);
Object[] args = {};
bool = (Boolean) method.invoke(bdDevice);//, args);// this invoke creates the detected devices paired.
} catch (Exception e) {
e.printStackTrace();
}
return bool.booleanValue();
};