嘿伙计们我对我正在做的计划有疑问。 我想配对两个蓝牙设备并显示一条消息以输入PIN。 有人可以帮帮我吗?非常感谢你。 此致
这是我的代码:
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) {
String ACTION_PAIRING_REQUEST = "android.bluetooth.device.action.PAIRING_REQUEST";
Intent intent = new Intent(ACTION_PAIRING_REQUEST);
String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE";
String device = null;
intent.putExtra(EXTRA_DEVICE, device);
String EXTRA_PAIRING_VARIANT = "android.bluetooth.device.extra.PAIRING_VARIANT";
int PAIRING_VARIANT_PIN = 10;
intent.putExtra(EXTRA_PAIRING_VARIANT, PAIRING_VARIANT_PIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
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);
}
}