2***@qq.com
2***@qq.com
  • 发布:2019-07-18 18:09
  • 更新:2019-07-20 09:04
  • 阅读:1198

关于 蓝牙 setPin 问题

分类:Native.js

做到了蓝牙自动配对,需要把原生代码:

Method removeBondMethod = btClass.getDeclaredMethod("setPin", new Class[]{byte[].class});  
Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice, new Object[]{str.getBytes()});

转成 js,整 两天了,new Class[]{byte[].class},这是个什么玩意,整不明白,请高手帮忙。
注:
btClass 是 bluetoothDevice 的 getClass()

上面原生的全部代码是,是ClsUtils类摘出来的:

    static public boolean setPin(Class<? extends BluetoothDevice> btClass, BluetoothDevice btDevice,  
                                 String str) throws Exception {  
        try {  
            Method removeBondMethod = btClass.getDeclaredMethod("setPin", new Class[]{byte[].class});  
            Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice, new Object[]{str.getBytes()});  
            Log.e("returnValue", "" + returnValue);  
        } catch (SecurityException e) {  
            // throw new RuntimeException(e.getMessage());  
            e.printStackTrace();  
        } catch (IllegalArgumentException e) {  
            // throw new RuntimeException(e.getMessage());  
            e.printStackTrace();  
        } catch (Exception e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }  
        return true;  

    }

下面是调用:

....  
btDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);  
if (action.equals("android.bluetooth.device.action.PAIRING_REQUEST")) {  
            //再次得到的action,会等于PAIRING_REQUEST  
            Log.d(TAG, "action2=" + action);  
            if (btDevice.getName().equals("MPT-II")) {  
                Log.d(TAG, "OKOKOK");  
                try {  
                    //3.调用setPin方法进行配对...  
                    boolean ret = ClsUtils.setPin(btDevice.getClass(), btDevice, pin);  

                } catch (Exception e) {  
                    // TODO Auto-generated catch block  
                    e.printStackTrace();  
                }  
            } else  
                Log.d("提示信息", "这个设备不是目标蓝牙设备");  

        }
2019-07-18 18:09 负责人:无 分享
已邀请:
2***@qq.com

2***@qq.com (作者) - 嗯嗯嗯,撂了吧,我写bug呢。

。。现在 hbuilder 是不是没人在用了?

该问题目前已经被锁定, 无法添加新回复