unable to make connection between 2 device bluetooth android

前端 未结 4 594
甜味超标
甜味超标 2021-01-31 04:02

I have tried to connect two devices by using the Android Bluetooth Chat example on the Android developer site. It\'s only connecting from one of the devices and when I am tryi

4条回答
  •  难免孤独
    2021-01-31 04:29

    Saurabh, make this change please and watch it work:

                    if (Build.VERSION.SDK_INT < 9) { // VK: Build.Version_Codes.GINGERBREAD is not accessible yet so using raw int value
                    // VK: 9 is the API Level integer value for Gingerbread
                    try {
                        tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                } else {
                    Method m = null;
                    try {
                        m = device.getClass().getMethod("createInsecureRfcommSocketToServiceRecord", new Class[] { UUID.class });
                    } catch (NoSuchMethodException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    try {
                        tmp = (BluetoothSocket) m.invoke(device, (UUID) MY_UUID);
                    } catch (IllegalAccessException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
    

提交回复
热议问题