Androidフォン/タブレット(4.0.3)と、イヤリングリーダーであるBluetoothデバイス(Destron Fearring DTR3E、知りたい場合に備えて、私はあなたとは思わない)との間でBluetooth通信を確立しようとしています行う)。
ブルートゥース設定から電話をリーダーとペアリングしました(リーダーにはタグにペアリングパスコードがあります)。もちろんブルートゥースはオンになっており、BluetoothServerSocketを使用してデバイスからの読み取りをリッスンしようとしています。問題は、受け入れ呼び出しが返されないことです。そのため、明らかに私は何か間違ったことをしています。通信は RFCOMM を使用して行われます。
コード:
private class AcceptThread extends Thread {
private final BluetoothServerSocket mmServerSocket;
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
String uuid = "00001101-0000-1000-8000-00805F9B34FB";
tmp = bluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord("pdfParserServer", UUID.fromString(uuid));
} catch (Exception e) {
e.printStackTrace();
}
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) {
break;
}
// If a connection was accepted
if (socket != null) {
// Do work to manage the connection (in a separate thread)
try {
mmServerSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
}
/** Will cancel the listening socket, and cause the thread to finish */
public void cancel() {
try {
mmServerSocket.close();
} catch (IOException e) { }
}
}
足りないものはありますか?
ありがとうございました!