device.createInsecureRfcommSocketToServiceRecord无法正常工作 [英] device.createInsecureRfcommSocketToServiceRecord doesn't work properly

查看:66
本文介绍了device.createInsecureRfcommSocketToServiceRecord无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里下载了BluetoothChat示例项目: https://android.googlesource.com/platform/development/+/master/samples/BluetoothChat?autodive = 0%2F

I dowloaded the BluetoothChat sample project here : https://android.googlesource.com/platform/development/+/master/samples/BluetoothChat?autodive=0%2F

事实是,当我在两个设备(未配对)上启动该应用程序时,它应该连接两个设备,而不要求配对两个设备,不是吗?实际上,当我尝试连接两个设备(未配对)时,它要求配对设备.我的意思是,BluetoothChatService.java中有此功能,应该创建一个不安全的套接字.但是看来,这没有完成他的工作吗?

The fact is, when I'm launching the app on two devices (which are NOT paired), it should connect the two devices WITHOUT asking for pairing the two devices, shouldn't it ? And in fact, when I'm trying to connect the two devices (which are NOT paired), it's asking to pair the devices . I mean, there is this function in BluetoothChatService.java which should create an insecure socket . But it seems, that it doesn't do his job ?

   /**
    * This thread runs while attempting to make an outgoing connection
    * with a device. It runs straight through; the connection either
    * succeeds or fails.
    */
   private class ConnectThread extends Thread {
       private final BluetoothSocket mmSocket;
       private final BluetoothDevice mmDevice;
       private String mSocketType;

       public ConnectThread(BluetoothDevice device, boolean secure) {
           mmDevice = device;
        BluetoothSocket tmp = null;
        mSocketType = secure ? "Secure" : "Insecure";

        // Get a BluetoothSocket for a connection with the
        // given BluetoothDevice
        try {
            if (secure) {
                tmp = device.createRfcommSocketToServiceRecord(
                        MY_UUID_SECURE);
            } else {
                tmp = device.createInsecureRfcommSocketToServiceRecord(
                        MY_UUID_INSECURE);
            }
        } catch (IOException e) {
            Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e);
        }
        mmSocket = tmp;
    }

有人可以解释一下为什么要求配对两个设备吗?方法createInsecureRfcommSocketToServiceRecord不应要求配对未配对的设备,应该吗?X)我真的很困惑.

Can somebody explain me why it asks to pair the two devices ? The method createInsecureRfcommSocketToServiceRecord shouldn't ask for pairing unpaired devices , should it ? x) I'm really confused .

推荐答案

createInsecureRfcommSocketToServiceRecord()具有设备用于通信的密钥不安全",在蓝牙2.1以下,未加密.那就是不安全".

createInsecureRfcommSocketToServiceRecord() has of "insecure" the key the devices are using to communicate, which is, below Bluetooth 2.1, not encrypted. That is what is "unsecure".

但是,它不会改变以下事实:如果配对数据库中还没有MAC地址,将始终显示提示.

But it does not change the fact that if the MAC address is not already in the pairing database there will always be the prompt.

是的,它会提示.

这篇关于device.createInsecureRfcommSocketToServiceRecord无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆