private class ConnectThread extends Thread {
private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
public ConnectThread(BluetoothDevice device){
Log.i(TAG, "ConnectThread");
Log.i("wang",device + "12345");
mmDevice = device;
BluetoothSocket tmp = null;
try {
//建立于蓝牙设备通道
//tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
tmp = (BluetoothSocket) (device.getClass().getMethod("createRfcommSocket",
new Class[] {int.class})).invoke(device, 1);
// tmp = device.createRfcommSocketToServiceRecord(
// MY_UUID);
} catch (Exception e) {
e.printStackTrace();
}
mmSocket = tmp;
Log.i(TAG, "mmSocket "+(mmSocket==null)+"");
} public void run() {
// Log.i(tag, "++ConnectThread.run()++"); // mAdapter.cancelDiscovery(); try {
Log.i(TAG, "正在连接服务器");
mmSocket.connect();
Log.i(TAG, "连接服务器成功");
} catch (IOException e) {
Log.i(TAG, "连接失败信息是"+e.getMessage());
try {
mmSocket.close();
} catch (IOException e2) {
e2.printStackTrace();
}
connectionFailed();
return;
}
synchronized (BluetoothService.this) {
mConnectThread = null;
} connected(mmSocket, mmDevice);
} public void cancel() {
// Log.i(tag, "++ConnectThread.cancel()++");
try {
mmSocket.close();
} catch (IOException e) {
// Log.e(tag, "ConnectThread.cancel()\n" + e.getMessage());
}
}
}
private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
public ConnectThread(BluetoothDevice device){
Log.i(TAG, "ConnectThread");
Log.i("wang",device + "12345");
mmDevice = device;
BluetoothSocket tmp = null;
try {
//建立于蓝牙设备通道
//tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
tmp = (BluetoothSocket) (device.getClass().getMethod("createRfcommSocket",
new Class[] {int.class})).invoke(device, 1);
// tmp = device.createRfcommSocketToServiceRecord(
// MY_UUID);
} catch (Exception e) {
e.printStackTrace();
}
mmSocket = tmp;
Log.i(TAG, "mmSocket "+(mmSocket==null)+"");
} public void run() {
// Log.i(tag, "++ConnectThread.run()++"); // mAdapter.cancelDiscovery(); try {
Log.i(TAG, "正在连接服务器");
mmSocket.connect();
Log.i(TAG, "连接服务器成功");
} catch (IOException e) {
Log.i(TAG, "连接失败信息是"+e.getMessage());
try {
mmSocket.close();
} catch (IOException e2) {
e2.printStackTrace();
}
connectionFailed();
return;
}
synchronized (BluetoothService.this) {
mConnectThread = null;
} connected(mmSocket, mmDevice);
} public void cancel() {
// Log.i(tag, "++ConnectThread.cancel()++");
try {
mmSocket.close();
} catch (IOException e) {
// Log.e(tag, "ConnectThread.cancel()\n" + e.getMessage());
}
}
}
解决方案 »
- android activity动画切换效果 真机一闪而过,模拟器正常
- 关于滚动停止在View中异步加载图片的问题
- MediaRecorder类中setVideoFrameRate方法的问题
- APN默认设置
- Android OOM问题
- 仿ios的桌面浮窗控制!请大神们告诉源码最好有注释,又或者是帮忙反编译一下然后加上详细的注释!!!!大恩没齿难忘!!!!!
- android 如何 获取当前『前台』正在运行的程序名?
- 获取优酷、搜狐视频源地址的方法
- 请问, msg.sendToTarget(); 往什么地方发?
- 那些c++搞android 的,后来都怎么样了。
- 来高手推荐几本关于界面布局详解和Adapter详解的书!
- adb push 如何获得进度
,他们轮着来,头疼啊