public class ConnectThread extends Thread
{
private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
private final OutputStream mmOutStream;
private UUID uuid = UUID.randomUUID();
private byte[] temp;
public ConnectThread(BluetoothDevice device,byte[] temp)
{
BluetoothSocket socket = null;
OutputStream tmpOut = null;
mmDevice = device;
this.temp = temp;
try
{
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
socket = (BluetoothSocket) m.invoke(device, 1);
tmpOut = socket.getOutputStream();
}
catch (Exception e) { }
mmSocket = socket;
mmOutStream = tmpOut;
}
public void run()
{ enter code here
try
{
mmSocket.connect();
write(temp);
}
catch (IOException connectException)
{
try
{
mmSocket.close();
}
catch (IOException closeException)
{ }
return;
}
}
public void write(byte[] bytes)
{
try
{
mmOutStream.write(bytes);
mmOutStream.flush();
mmOutStream.close();
}
catch (IOException e) { }
}
public void cancel()
{
try
{
mmSocket.close();
}
catch (IOException e) { }
}
}
我正在尝试将txt文件传输到另一台设备。我将蓝牙设备和消息(以字节为单位)传递给此类并从主要活动开始线程。扫描后,显示和配对的设备也在工作。我没有在代码中得到任何异常。但我没有收到档案。
为什么我没有在其他手机上收到文件?
请有人帮助我。
谢谢,法拉兹