小编Pas*_*oid的帖子

如何在Android上以编程方式配对和连接HID蓝牙设备(蓝牙键盘)

我能够配对蓝牙键盘但无法连接以使其成为输入设备.我浏览了开发者网站提供的文档 - http://developer.android.com/guide/topics/connectivity/bluetooth.html#Profiles

它表示Android蓝牙API提供以下蓝牙配置文件的实现,但您可以实现接口BluetoothProfile编写自己的类以支持特定的蓝牙配置文件.

  • 耳机
  • A2DP
  • 健康设备

没有关于如何为HID蓝牙设备(键盘)实现BluetoothProfile的文档

Android本身已经为HID设备实现了蓝牙连接,但这些API是隐藏的.我也试过反思来使用它们.我没有得到任何错误,但键盘没有作为输入设备连接.这就是我所做的 -

private void connect(final BluetoothDevice bluetoothDevice) {
    if(bluetoothDevice.getBluetoothClass().getDeviceClass() == 1344){
        final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
            BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {
                @Override
                public void onServiceConnected(int profile, BluetoothProfile proxy) {
                    Log.i("btclass", profile + "");

                    if (profile == getInputDeviceHiddenConstant()) {
                        Class instance = null;
                        try {
                            //instance = Class.forName("android.bluetooth.IBluetoothInputDevice");
                            instance = Class.forName("android.bluetooth.BluetoothInputDevice");
                            Method connect = instance.getDeclaredMethod("connect", BluetoothDevice.class);
                            Object value = connect.invoke(proxy, bluetoothDevice);
                            Log.e("btclass", value.toString());
                        } catch (ClassNotFoundException e) {
                            e.printStackTrace();
                        } catch (InvocationTargetException …
Run Code Online (Sandbox Code Playgroud)

android bluetooth hid android-bluetooth

9
推荐指数
1
解决办法
8324
查看次数

如何获取访问我的应用程序的内容提供商的应用程序的包名称?

实际上,当任何其他应用程序从我的应用程序共享的内容提供程序中获取数据时,我想要某种广播

android android-contentprovider android-package-managers

4
推荐指数
2
解决办法
2402
查看次数

RecyclerView与StaggeredGridLayoutManager一起从Glide加载图像

我有表示问题RecyclerViewStaggeredGridLayoutManager其项包含一个imageview和所述图像中装入imageview使用glide.我面临的问题是,在图像加载后,它们不会交错并且尺寸相同,两列之间也存在很大的差距.如何在列中没有间隙的情况下改变图像的高度?

android staggered-gridview staggeredgridlayout android-recyclerview android-glide

3
推荐指数
2
解决办法
5221
查看次数