当前位置: 首页 > 知识库问答 >
问题:

连接到gatt服务器不工作在三星Galaxy Core Prime(Android 5.1.1)

尉迟栋
2023-03-14

我有一个BLE应用程序,可在Android 6.0及更高版本的设备上运行,但我在Samsung Galaxy Core Prime(Android 5.1.1)上有问题。调用ConnectGatt后没有发生任何事情,回调只接收到断开连接的状态。

我删去了适当的代码:

BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
final BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address);
Log.e("BluetoothLeService", "connect: connectGatt(this, false, mGattCallback)");
BluetoothGatt bluetoothGatt = device.connectGatt(this, false, mGattCallback);

private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
    @Override
    public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
        if (newState == BluetoothProfile.STATE_CONNECTED) {
            Log.e("BluetoothLeService", "onConnectionStateChange: STATE_CONNECTED");
        } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
            Log.e("BluetoothLeService", "onConnectionStateChange: STATE_DISCONNECTED");
        }
    }

    @Override
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    }

    @Override
    public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
    }

    @Override
    public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
    }

    @Override
    public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    }

    @Override
    public void onMtuChanged (BluetoothGatt gatt, int mtu, int status) {
    }
};

这是日志:

E/BluetoothLeService: connect: connectGatt(this, false, mGattCallback)
I/StatusBar: Icon Only
D/BluetoothGatt: connect() - device: CC:4B:73:22:9D:DB, auto: false
D/BluetoothGatt: registerApp()
D/BluetoothGatt: registerApp() - UUID=7d428718-b549-4021-8a45-9d3bd2afd462
D/BtGatt.GattService: registerClient() - UUID=7d428718-b549-4021-8a45-9d3bd2afd462
D/SamsungIME: Dismiss ExpandCandiate
D/PanelView: There is/are notification(s) 
D/CustomFrequencyManagerService: releaseDVFSLockLocked : Getting Lock type frm List : DVFS_MIN_LIMIT  frequency : 1248000  uid : 1000  pid : 2975  tag : ACTIVITY_RESUME_BOOSTER@4
I/Timeline: Timeline: Activity_windows_visible id: ActivityRecord{2bfa99a5 u0 com.streamunlimited.streamsdkdemo/.ui.setup.SetupDeviceActivity t43} time:3838458
W/ActivityManager: mDVFSHelper.release()
D/CustomFrequencyManagerService: acquireDVFSLockLocked : type : DVFS_MIN_LIMIT  frequency : 1248000  uid : 1000  pid : 2975  pkgName : ACTIVITY_RESUME_BOOSTER@8
D/BtGatt.GattService: onClientRegistered() - UUID=7d428718-b549-4021-8a45-9d3bd2afd462, clientIf=6
D/BluetoothLeService: Trying to create a new connection.
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6
D/BtGatt.GattService: clientConnect() - address=CC:4B:73:22:9D:DB, isDirect=true set own addr = false own addr type:0
D/BtGatt.btif: btif_get_device_type: Device [cc:4b:73:22:9d:db] type 3, addr. type 0
D/IOP_DB_BT: db_query_create: id EnforceMasterRole :: key KEY_BDADDR, value cc:4b:73:22:9d:db
D/IOP_DB_BT: db_query_add_key: key KEY_LMP_MFCT, value 15
D/IOP_DB_BT: db_query_add_key: key KEY_LMP_VER, value 9:24838
D/IOP_DB_BT: db_query_add_key: key KEY_DIR_ALL, value 1
D/IOP_DB_BT: db_query_execute: result 1
D/bluedroid-mrvl: bt_vnd_mrvl_if_op(L95): opcode = 7
I/SurfaceFlinger: id=153 Removed TetupScanAc (3/9)
I/SurfaceFlinger: id=153 Removed TetupScanAc (-2/9)
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@21558ec5 time:3838516
W/SurfaceFlinger: couldn't log to binary event log: overflow.
D/CustomFrequencyManagerService: releaseDVFSLockLocked : Getting Lock type frm List : DVFS_MIN_LIMIT  frequency : 1248000  uid : 1000  pid : 2975  tag : ACTIVITY_RESUME_BOOSTER@8
D/BatteryService: !@BatteryListener : batteryPropertiesChanged!
W/bt-btif: bta_gattc_conn_cback() - cif=4 connected=0 conn_id=4 reason=0x0004
W/bt-btif: bta_gattc_conn_cback() - cif=5 connected=0 conn_id=5 reason=0x0004
W/bt-btif: bta_gattc_conn_cback() - cif=6 connected=0 conn_id=6 reason=0x0004
D/BtGatt.GattService: onConnected() - clientIf=6, connId=0, address=CC:4B:73:22:9D:DB
D/BluetoothGatt: onClientConnectionState() - status=133 clientIf=6 device=CC:4B:73:22:9D:DB
E/BluetoothLeService: onConnectionStateChange: STATE_DISCONNECTED

看起来可疑的线条有:

W/bt-btif: bta_gattc_conn_cback() - cif=4 connected=0 conn_id=4 reason=0x0004
W/bt-btif: bta_gattc_conn_cback() - cif=5 connected=0 conn_id=5 reason=0x0004
W/bt-btif: bta_gattc_conn_cback() - cif=6 connected=0 conn_id=6 reason=0x0004

我发现原因4意味着:

PAGE TIMEOUT (0x04)
The Page Timeout error code indicates that a page timed out because of the
Page Timeout configuration parameter. This error code may occur only with the
Remote_Name_Request and Create_Connection commands.

在文档中https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=421043

还有这一行:

D/BluetoothGatt: onClientConnectionState() - status=133 clientIf=6 device=CC:4B:73:22:9D:DB

只是一个基于GATT_ERROR的宏:

https://android.googlesource.com/platform/external/bluetooth/bluedroid//android-4.4.4\u r2。0.1/stack/include/gatt\u api。H

我也尝试过nRF Connect应用程序,但它也无法连接:错误133(0x85):GATT错误

你知道这可能的原因和解决方案吗?谢谢

共有1个答案

南宫才艺
2023-03-14

错误状态133可能有各种原因,因为它是Android系统报告的一般错误。可能的原因:

  1. 当外围设备超出范围/在建立连接的瞬间关闭
  2. 当Android BLE堆栈无法正常工作时(有时关闭和打开蓝牙适配器和WiFi都有帮助)
  3. 当外设不正确符合BLE规范时
  4. 手机BLE驱动不够好的时候
  5. 其他(检查谷歌)

最简单的解决方法是,如果失败并出现此类错误,请重试连接。

我强烈建议使用Polidea的RxAndroidBle库来实现BLE通信,这非常有用。

如果您开始使用它,则可以尝试建立连接,如果连接失败,请使用操作员retryWhen重试。你可以从这个答案中得到一些线索。

 类似资料:
  • 运行后,Android部分返回connection be success(BluetoothGattCallback::onConnectionStateChange的参数为STATE_CONNECTED),但是linux中的程序(btgatt-server)没有得到任何响应,仍然阻止等待接受。(第485行)。 我还使用了另一个示例代码:l2cap-ble.c,结果完全相同。 有人能帮我吗?我的目

  • Android问题 一旦我的设备收到数据从GATT服务器,一次收到数据后,它被断开连接。我尝试了许多不同的方法,但都不起作用。我已经阅读了整个网址也...Android4.3蓝牙低能耗不稳定

  • 我正在尝试将大量文件从服务器A传输到服务器B。我已经在A上设置了FTP(使用FileZilla)。 当我尝试从PC连接到A时,它工作正常。但当我尝试从B连接到A时,它不起作用。FTP用户登录,但目录列表命令一直处于停滞状态。 防火墙端口21已打开。我尝试了多台服务器、不同的FTP客户端,但没有用。除了FileZilla,我还尝试了内置FTP服务的ISS,得到了相同的结果。 使用相同凭据从本地完美连

  • 我正在尝试连接到mysql工作台,但遇到以下错误 错误消息无法连接到数据库服务器 用户“root”从主机到服务器的连接尝试失败(位于127.0.0.1:3306:无法打开数据库)。 请:1。检查mysql是否正在服务器127.0.0.1上运行 检查mysql是否在端口3306上运行(注意:3306是默认值,但可以更改) 检查root是否具有从您的地址连接到127.0.0.1的权限(mysql权限定

  • 我已经实现了一个基于此Apache项目的FTP服务器:http://mina.apache.org/ftpserver-project/index.html 服务器旨在支持被动模式并进行相应配置。出于测试目的,我仅配置了一个被动端口(4244),但启动服务器后此端口上没有任何内容被监听。FTP服务器正在监听标准端口用于主动连接和SSL连接。 当尝试与FTP客户端连接时,我会收到以下错误(不足为奇)

  • 我正在为youtube api实现OAuth 2… 公共静态凭据authorize(列表范围,字符串credentialDatastore)引发IOException { } 它在本地工作。从逻辑上讲,我将回调URL更改为http://localhost:8081/CallBack..在本地工作正常,但当我使用公共IP部署到AWS服务器时,它不起作用。 显示地址已被用于8081异常,甚至没有重定向