gpt4 book ai didi

Android 4.0 蓝牙配对 : Need to enter password everytime

转载 作者:行者123 更新时间:2023-11-29 00:38:51 25 4
gpt4 key购买 nike

我在使用 Android 4 (ICS) 时遇到问题我的蓝牙应用程序连接到串行设备在 Android 3 上运行起来就像一个魅力。

但是,在使用 Android 4 时,每次连接到(已配对的)设备时都会显示“配对”对话框。

用户必须一遍又一遍地重新输入同一个密码。有什么方法可以抑制 Android 4 中的这种行为吗?这是一个新的错误吗?有解决办法吗? BluetoothDevice 是否需要某种适应 Android 4 的方式?我做错了什么?

 /**
* 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;
}

提前致谢

顺便说一句:如何确保在连接之前停止从我的平板电脑到此蓝牙设备的所有其他连接?

最佳答案

我认为这不是您的软件的问题。在我拿到带有 ICS 的手机后,我在 RunKeeper 和我的 Polar BT 心率监测器上看到了同样的问题。我在使用 ROM 或 CM7 的 HTC Desire 上没有遇到过这个问题。

关于Android 4.0 蓝牙配对 : Need to enter password everytime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10873215/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com