getItemAtPosition()
方法返回一个对象。
将类型转换为BluetoothDevice
无效。
另外,它显示运行时错误:
FATAL EXCEPTION: main Process: com.example.charmi.yolo, PID: 14689
java.lang.ClassCastException: java.lang.String cannot be cast to android.bluetooth.BluetoothDevice
在线:
BluetoothDevice btDevice = (BluetoothDevice)listDevicesFound.getItemAtPosition(position);
谢谢!
答案 0 :(得分:0)
试试这个。
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
List<String> s = new ArrayList<String>();
for(BluetoothDevice bt : pairedDevices)
s.add(bt.getName());
String bluetootPosition= s.get(position);