Android 4(ICS)に問題がありますシリアルデバイスに接続するBluetoothアプリはAndroid3の魅力のように機能します。
ただし、Android 4を使用している場合は、(ペアリング済みの)デバイスに接続するたびに[ペアリング]ダイアログが表示されます。
ユーザーは同じピンを何度も再入力する必要があります。Android 4でこの動作を抑制する方法はありますか?それは新しいバグですか?回避策はありますか?BluetoothDeviceはAndroid4に何らかの適応が必要ですか?私は何が間違っているのですか?
/**
* Start the ConnectThread to initiate a connection to a remote bluetoothDevice.
*/
public synchronized InitResponse init() {
if (D) Log.d(TAG, "init to: " + bluetoothDevice);
setState(State.CONNECTING);
try {
if (D) Log.i(TAG, "Trying to create RfcommSocket using reflection");
Method m = bluetoothDevice.getClass().getMethod("createRfcommSocket",
new Class[] { int.class });
bluetoothSocket = (BluetoothSocket)m.invoke(bluetoothDevice, 1);
} catch (Exception e) {
if (D) Log.w(TAG, "Reflection failed.", e);
if (D) Log.i(TAG, "Trying to create RfcommSocket using UUID");
try {
bluetoothSocket = bluetoothDevice.createRfcommSocketToServiceRecord(READER_UUID);
} catch (IOException e2) {
Log.e(TAG, "create() failed", e2);
disconnect();
return InitResponse.READER_NOT_FOUND;
}
}
if (D) Log.i(TAG, "Bluetooth Socket: " + bluetoothSocket);
if (D) Log.i(TAG, "Trying to connect.");
try {
bluetoothAdapter.cancelDiscovery();
if (D) Log.i(TAG, "Cancelled discovery.");
if (D) Log.i(TAG, "Attempting to connect.");
bluetoothSocket.connect(); // Causes pairing dialog everytime I call it.
} catch (IOException e) {
if (D) Log.w(TAG, "Error while connecting.");
// Close the socket
try {
bluetoothSocket.close();
} catch (IOException e2) {
Log.e(TAG, "unable to close() socket during connection failure", e2);
} finally {
disconnected();
}
return InitResponse.CONNECTION_ERROR;
}
if(D) Log.d(TAG, "Connected to bluetoothReader " + bluetoothDevice + " established.");
try {
inputStream = bluetoothSocket.getInputStream();
if(D) Log.d(TAG, "Input Stream: " + inputStream);
outputStream = bluetoothSocket.getOutputStream();
if(D) Log.d(TAG, "Output Stream: " + outputStream);
} catch (IOException e) {
Log.e(TAG, "Temp sockets not created", e);
disconnected();
return InitResponse.CONNECTION_ERROR;
}
if (D) Log.i(TAG, "Setting state to CONNECTED");
setState(State.CONNECTED);
if (D) Log.i(TAG, "Init successfull.");
return InitResponse.SUCCESS;
}
前もって感謝します
ところで:接続する前に、タブレットからこのbluetoothDeviceへの他のすべての接続が停止していることを確認するにはどうすればよいですか?