BluetoothDevice.ConnectGatt()与交通参数 [英] BluetoothDevice.ConnectGatt() with transport parameter

查看:4149
本文介绍了BluetoothDevice.ConnectGatt()与交通参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始与Android和设置在Android的Studio中的API 21项目中使用蓝牙LE。

I just started with Android and set up an API 21 project in Android Studio using Bluetooth LE.

挖掘BluetoothDevice类显示我ConnectGatt的两个签名()方法:

Digging into BluetoothDevice shows me two signatures of ConnectGatt() method:

public BluetoothGatt connectGatt(Context context, boolean autoConnect,
                                 BluetoothGattCallback callback)

public BluetoothGatt connectGatt(Context context, boolean autoConnect,
                                 BluetoothGattCallback callback, int transport)

我想使用第二个,但构建失败:

I'd like to use the second one but the build fails:

错误:(127,26)错误:方法connectGatt类BluetoothDevice类   不能被应用到给定的类型;需要:   上下文,布尔,BluetoothGattCallback发现:   上下文,布尔,BluetoothGattCallback,INT原因:实际的和正式的   参数列表的长度不同

Error:(127, 26) error: method connectGatt in class BluetoothDevice cannot be applied to given types; required: Context,boolean,BluetoothGattCallback found: Context,boolean,BluetoothGattCallback,int reason: actual and formal argument lists differ in length

这似乎编译器设置不匹配源$ C ​​$ c在Android的工作室。

It seems the compiler settings don't match the source code in Android Studio.

我该如何解决这个问题?

How can I fix this?

推荐答案

更​​新! 我可能已经找到了解决这一缺陷是困扰我们很多的方式。由于Android默认为L2CAP频道5连接上与iOS拒绝这样做。这是因为在iOS广告包了一下标志,指示BR / EDR。

UPDATE!!! I may have found a way around this defect that is bothering us so much. Since android defaults to connecting on L2CAP Channel 5 with iOS refuses to do. This is due to a bit flag on iOS advertising packet indicating BR/EDR.

回顾了Android code我发现connectGatt()函数有一个隐藏的INT运输变量,将允许您使用AUTO或特定LE或BR / EDR只。

Reviewing the android code I found that connectGatt() function has a hidden int TRANSPORT variable that will allow you to use AUTO or specific LE or BR/EDR only.

由于某些原因,这是在机器人工作室BluetoothDevice.java文件中可用,但在Android code引用未列​​出。当您尝试使用它,它给你一个错误。如果有人可以解释我们如何解决编译器在Android工作室使用TRANSPORT_LE选项,而不是TANSPORT_AUTO我以为是被用来​​编译我们code。

For some reason, this is available in the BluetoothDevice.java file in android studio, but not listed in the android code reference. When you attempt to use this, it gives you an error. If someone can explain how we can fix the compiler on android studio to compile our code using the TRANSPORT_LE option instead of TANSPORT_AUTO which I assume is being used.

确定这是回,让我们的工作!

Ok this is back on, let's get to work!

这篇关于BluetoothDevice.ConnectGatt()与交通参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆