Java android Bluetooth服务器在发现中不可见
所以我写了一个简单的蓝牙服务器,但我不能看穿蓝牙设置,也不能看穿其他davice的蓝牙广播接收器。 我想创建一个叫phoneTo的蓝牙davice 这是我的服务器代码Java android Bluetooth服务器在发现中不可见,java,android,Java,Android,所以我写了一个简单的蓝牙服务器,但我不能看穿蓝牙设置,也不能看穿其他davice的蓝牙广播接收器。 我想创建一个叫phoneTo的蓝牙davice 这是我的服务器代码 class AcceptThread extends Thread { private final BluetoothServerSocket mmServerSocket; public AcceptThread() { BluetoothServerSocket tmp = null; try {
class AcceptThread extends Thread {
private final BluetoothServerSocket mmServerSocket;
public AcceptThread() {
BluetoothServerSocket tmp = null;
try {
// MY_UUID is the app's UUID string, also used by the client code.
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
tmp = bluetoothAdapter.listenUsingRfcommWithServiceRecord("phonTo", UUID.randomUUID());//phonTo is the name I want the device to have
} catch (IOException e) {
Log.e("ok", "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("ok", "Socket's accept() method failed", e);
break;
}
而我只是简单地运行线程
AcceptThread th=new AcceptThread();
new Thread(th).start();
但无法通过蓝牙看到任何正在扫描的设备。
我用了
作为我的学习资源