我目前正在开发一个涉及两个设备之间的bluetooth
连接的应用程序。当我单击连接时,另一部电话显示它已连接,但我的电话未连接。
public void connectToDevice(BluetoothDevice device){
try {
Toast.makeText(connectpage.this, "creating socket", Toast.LENGTH_SHORT).show();
UUID ui=UUID.fromString("00001112-0000-1000-8000-00805F9B34FB");
mmSocket = device.createRfcommSocketToServiceRecord(ui);
mBluetoothAdapter.cancelDiscovery();
} catch (IOException e){}
try{
Toast.makeText(connectpage.this, "pre-connection", Toast.LENGTH_SHORT).show();
mmSocket.connect();
flag=1;
Toast.makeText(connectpage.this, "post-connection", Toast.LENGTH_SHORT).show();
ConnectedThread(mmSocket);
//byte[] connv=convby();
String s="hii";
try{write(s.getBytes());
}catch(Exception e){Toast.makeText(connectpage.this, "error in write", Toast.LENGTH_SHORT).show();}
} catch (IOException e){
try{
mmSocket.close();
Toast.makeText(connectpage.this, "error", Toast.LENGTH_SHORT).show();
} catch (IOException exception){}
}
}