2

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への他のすべての接続が停止していることを確認するにはどうすればよいですか?

4

2 に答える 2

1

これはあなたのソフトウェアの問題ではないと思います。ICSを搭載した電話を入手した後、RunKeeperとPolarBT心拍数モニターで同じ問題が発生しています。ストックROMまたはCM7を使用したHTCDesireではその問題は発生していません。

于 2012-06-06T17:56:37.627 に答える
1

同様の問題がありました:AndroidICSでのBluetooth接続ができません

安全でないソケットを取得してみてください。

bluetoothSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(READER_UUID);
于 2012-06-21T09:41:08.193 に答える