简体   繁体   English

如何检查设备是否支持 BLE Gatt 客户端模式?

[英]how to check BLE Gatt Client Mode is supported by device?

In android, I have used BLE both mode as Peripheral and Client.在 android 中,我使用 BLE 两种模式作为外设和客户端。 But I want to check isBLeGattClientSupported()但我想检查isBLeGattClientSupported()

As we know some devices in android are not capable to act as BLE Gatt Client so jut wants to throw an exception that such device is not able to act as client.正如我们所知,android 中的某些设备无法充当 BLE Gatt 客户端,因此只想抛出此类设备无法充当客户端的异常。

I have the rest of the past for BLE my code is working fine for both mode, but stuck when I said to my device to act as a client and that device is not capable to act as the client.我有 BLE 过去的其余部分,我的代码在两种模式下都可以正常工作,但是当我告诉我的设备充当客户端并且该设备无法充当客户端时卡住了。

This is straight from the android developer guide -这是直接来自android 开发者指南-

at run-time you can determine BLE availability by using PackageManager.hasSystemFeature():在运行时,您可以使用 PackageManager.hasSystemFeature() 确定 BLE 可用性:

The java example provided (a Kotlin example is also on the same page) to check the same is as follows -提供的 java 示例(Kotlin 示例也在同一页面上)检查相同的内容如下 -

if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
    Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
    finish();
}

This way you can check if your device supports BLE and throw an exception as required这样您就可以检查您的设备是否支持 BLE 并根据需要抛出异常

所有具有运行 Android 4.3 以上版本的蓝牙芯片(4.0 及更高版本)的 Android 设备都支持 BLE,并且所有这些设备都支持充当BluetoothGatt客户端以及文档中提到的BluetoothGattServer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM