请教一下,Android 平板作为主机,蓝牙连接HID keyboard 设备

C_S_D_N_LHT 2024-04-16 11:29:13
private final BluetoothProfile.ServiceListener connect = new BluetoothProfile.ServiceListener() {

    @Override
    public void onServiceConnected(int profile, BluetoothProfile proxy) {
        //BluetoothProfile proxy这个已经是BluetoothInputDevice类型了
        try {
            proxys = proxy;
                if (device != null) {
                    Method method = proxy.getClass().getDeclaredMethod("connect");
                    method.invoke(device);
                }
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onServiceDisconnected(int profile) {

    }
};

 

反射获取 connect 方法时,报错:java.lang.NoSuchMethodException: android.bluetooth.BluetoothHidHost.connect []

...全文
636 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

80,354

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧