Android 与蓝牙键盘两种方式都连接不上,可是与hc06可以连接,uuid的问题还是其他问题

class ItemClickEvent implements AdapterView.OnItemClickListener {

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {
    btAdapt.cancelDiscovery();
        String str = lstDevices.get(arg2);
        String[] values = str.split("\\|");
        String address=values[1];
        Log.e("address",values[1]);

        uuid = UUID.fromString(SPP_UUID);
        Log.e("uuid",uuid.toString());

        BluetoothDevice btDev = btAdapt.getRemoteDevice(address);//"00:11:00:18:05:45"


            Method m;
            try {
                m = btDev.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
                btSocket = (BluetoothSocket) m.invoke(btDev, Integer.valueOf(1));

            } catch (SecurityException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (NoSuchMethodException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }       
        btAdapt.cancelDiscovery();
        try {
            //btSocket = btDev.createRfcommSocketToServiceRecord(uuid);             
            btSocket.connect();             
            Log.e(TAG, " BT connection established, data transfer link open.");

            Toast.makeText(Activity01.this, "连接成功,进入控制界面", Toast.LENGTH_SHORT).show();
            //setTitle("连接成功");
            but4.setClickable(true); 
            but3.setClickable(true);
            //打开控制继电器实例


        } catch (IOException e) {
            // TODO Auto-generated catch block
            Log.e(TAG, " Connection failed.", e);   
            //Toast.makeText(getApplicationContext(), "连接失败", Toast.LENGTH_SHORT);
          setTitle("连接失败..");
        }   
}
}
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问