//作为服务器连接
private class AcceptThread extends Thread {
private final BluetoothServerSocket mmServerSocket;
private static final String NAME = "YourBluetoothServerName";
private static final String TAG = "MyBluetoothServer";
public AcceptThread() {
// Use a temporary object that is later assigned to mmServerSocket
// because mmServerSocket is final.
BluetoothServerSocket tmp = null;
try {
// MY_UUID is the app's UUID string, also used by the client code.
tmp = bluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
} catch (IOException e) {
Log.e(TAG, "Socket's listen() method failed", e);
}
mmServerSocket = tmp;
}
public void run() {
BluetoothSocket socket = null;
// Keep listening until exception occurs or a socket is returned.
while (true) {
try {
socket = mmServerSocket.accept();
} catch (IOException e) {
Log.e(TAG, "Socket's accept() method failed", e);
break;
}
if (socket != null) {
// A connection was accepted. Perform work associated with
// the connection in a separate thread.
manageMyConnectedSocket(socket);
try {
mmServerSocket.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
break;
}
}
}
private void manageMyConnectedSocket(BluetoothSocket socket) {
}
// Closes the connect socket and causes the thread to finish.
public void cancel() {
try {
mmServerSocket.close();
} catch (IOException e) {
Log.e(TAG, "Could not close the connect socket", e);
}
}
}
任务:安卓蓝牙APP
1、把发现和启用可检测性部分做完了
基于上周的内容,增加启用可检测性的方法
这里是将本设备开启被检测权限300s
下午本来想一步到位,我以为在app外部进行蓝牙配对成功以后,可以直接写连接控制的方法,结果我试了下来是行不通的。
只能老老实实的一步一步,这里我本来想在发现部分把扫描到的设备通过RecylcerView的方法展示出来的,后面想了一下没有必要
2、连接部分
由于是两个APP,我在TV 端作为服务器,然后进行连接
问题就是出在这里了,还在排查,,,
明日任务:把连接做好,争取实现数据传输成功