当前位置: 首页 > 知识库问答 >
问题:

Android4.0蓝牙配对:每次都需要输入密码

戈博易
2023-03-14

我在Android4(ICS)上有个问题,我的蓝牙应用程序连接到一个串行设备上,在Android3上就像一个魅力。

然而,当使用Android4时,每次我连接到(已经配对的)设备时,它都会显示“配对”对话框。

用户必须一遍又一遍地重新输入相同的pin。在Android4中有什么方法可以抑制这种行为吗?是新的虫子吗?附近有工作吗?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的所有其他连接在连接之前都被停止?

共有1个答案

郎雅昶
2023-03-14

我不认为这是你的软件的问题。我看到RunKeeper和我的Polar BT心率监测器在我得到一部带有ICS的手机后也有同样的问题。我没有遇到HTC Desire与库存ROM或CM7问题。

 类似资料:
  • 问题内容: 每次我尝试将任何内容推送到GitHub时,它都会询问我地址,然后它要求密码。有没有办法使它自动化? 我正在使用Linux Ubuntu。 问题答案: 您可以用来记住密码(通常,Gnome会自动为您运行密码)。 从现在开始,在您运行此程序的终端中,您的密码将被记住。 理想情况下,它会自动运行,因此在gnome中运行的所有shell都可以工作。查看Gnome Keyring 。

  • 我目前正在构建一个运行在Windows 10 IoT Core上的无头UWP应用程序。我需要能够通过蓝牙(RFCOMM)将移动设备连接到信息亭以获取数据。我需要能够从移动设备启动配对。 我已经尝试了所有UWP蓝牙示例应用程序,但主要是尝试设备枚举和配对C#示例-特别是场景9-自定义设备配对。我可以使用引脚成功配对到头部UWP应用程序,但我无法成功配对到无头UWP应用程序-当我尝试启动配对时,我要么

  • 嗨,我要开发一个应用程序,所以我有一个设备(服务器)与3个客户端。我做了所有的验证,打开蓝牙,找到设备,所有的工作都很好。但当我要连接一个设备时,我不知道会发生什么。 我正在使用下一个代码,当我单击一个我想连接它的设备时。我只有我的应用程序在母设备中。 这里我有一个问题,如果它没有配对会发生什么?如果我尝试连接,它会自动配对吗? 我的UUID是:“00001101-0000-1000-8000-0

  • 我正在Visual Studio 2015中用C语言为运行Windows IoT Core的Raspberry PI 2设备开发。 对于我的应用程序,我需要配对和取消配对蓝牙设备 我可以获得配对/未配对/所有蓝牙设备的列表吗<类似于内置管理网站的蓝牙页面(http://[设备IP]:8080/Bluetooth.htm) 我找到了一个例子(https://github.com/Microsoft/

  • 我正在执行多个ajax调用,我想在显示表单之前完成所有这些调用。如果有错误,我想停止处理,只显示遇到的第一个错误。我谷歌了很多文章,包括StackOverflow上的文章,这些文章展示了如何链接当时的语句。但是似乎我必须给每个语句都附加一个捕获,否则只捕获最后一个语句中的错误。在本例中,Lookup是一个返回promise的异步调用,ShowError处理错误: 假设至少有一个错误,是否有任何方法

  • 这是菜单类 import java.util.Scanner; 公共类菜单{private String[]Menu_options; } 这是我使用的菜单驱动程序 公共类 Menutester { } 我第一次输入一些东西时,它根本不会重新生成,当我尝试在eclipse中调试它时,它会给我错误FileNotFoundException(Throwable)。(字符串)行:第一次输入195。 这就