- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我是 Android 应用程序开发的初学者。我已经尝试阅读文档,但一无所获(Android 教程中的函数,例如 StartLeScan()
已被弃用,等等...)
是否有一个返回蓝牙设备列表的简单函数?
类似于 getDevices()
->(设备列表)?
谢谢
最佳答案
基本上,这取决于您所针对的 Android 版本。因为 api 在 lollipop (21) 中发生了一些变化。
在您的 Activity 中,获取蓝牙适配器
BluetoothManager bm = (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE)
BluetoothAdapter mBluetoothAdapter = bm.getAdapter();
// Ensures Bluetooth is available on the device and it is enabled. If not,
// displays a dialog requesting user permission to enable Bluetooth.
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
然后你应该检查你的目标是哪个android版本
int apiVersion = android.os.Build.VERSION.SDK_INT;
if (apiVersion > android.os.Build.VERSION_CODES.KITKAT){
BluetoothLeScanner scanner = mBluetoothAdapter.getBluetoothLeScanner();
// scan for devices
scanner.startScan(new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
// get the discovered device as you wish
// this will trigger each time a new device is found
BluetoothDevice device = result.getDevice();
}
});
} else {
// targetting kitkat or bellow
mBluetoothAdapter.startLeScan(new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
// get the discovered device as you wish
}
});
// rest of your code that will run **before** callback is triggered since it's asynchronous
不要忘记在 list 中添加权限
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
关于android - 在 Android 中检测蓝牙 Le 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28365260/
当我向我的安装程序添加依赖项时,我总是留下文件的硬编码路径。 根据 this blog ,解决此问题的唯一方法是使用 ISProjectFolder 变量手动更改 ISL 文件中的硬编码路径。这没有任
我想开发像蓝牙 LE 外围设备这样的应用程序,它停止在与蓝牙 LE 中央设备连接时做广告,并限制与多个蓝牙 LE 中央设备连接的蓝牙 LE 外围设备。 一个蓝牙 LE 外围设备一次只能与一个蓝牙 LE
示例代码: # Step 1 $start = get-date for($i=1; $i -le 1000000; $i++){} $end = get-date ($end-$start).Tot
在Basic customisation ,python 文档说明了比较方法: [no swapped-argument versions of these methods]; rather, __l
蓝牙双模设备是否可以在与 BT LE 设备配对的同时被经典蓝牙发现?如果设备不能同时运行这两种模式也没关系,但我真的应该在这些模式之间切换芯片吗?我只是在 BT 4 Core 规范中找不到答案 最佳答
我正在尝试使用 fscanf 从输入文件中读取 3 个 double 值,但在尝试这样做时遇到了段错误。我的代码如下: FILE * infile = fopen(argv[1], "r");
我的域指向另一个网站,我想为其安装 LE 证书,这可能吗,或者我的域应该链接到服务器? 最佳答案 letsencrypt 不允许安装非 NS 指向,因为它检查反向验证,所以它会失败 关于wordpre
在我的 Android(API 版本 21 及更高版本)Bluetooth LE 应用程序中,该应用程序首先使用 BluetoothLeScanner 和 ScanCallback 对象扫描外围设备。
我正在使用 Xamarin 和这个 BLE 插件构建一个 iOS 应用程序: https://github.com/aritchie/bluetoothle 我只是通过 BLE 广播一个 UUID,它
我可以在点击时同时扫描蓝牙和蓝牙 LE 设备吗? 最佳答案 答案是否定的。 原文来自: http://developer.android.com/guide/topics/connectivity/b
关于 Dennis Mathews answer,您如何在 iOS 上指定经典蓝牙而不是 LE?有没有和Core Bluetooth Framework?不同的api 最佳答案 Joels 有一种在
我有一个使用 BLE 的应用程序。在某些情况下,例如当安装在 iPhone 6 上时,应用程序正在运行并且不请求使用 BLE 的许可。 在其他情况下,比如我的 iPad Air,应用程序开始运行,并且
我尝试使用 Bluetooth LE 检测设备,按照 Xamarin 库中的说明执行此操作,但设备发现 0 包括 android 中的必要声明。将扫描时间增加到 30 秒,但没有任何效果。支持蓝牙,版
配对“普通”蓝牙设备和配对蓝牙 LE 设备之间是否存在任何(大)技术差异? 我找到了很多关于蓝牙 LE 配对的信息,但没有正常的?例如 Info 1 . 那么普通蓝牙的这个信息也正确吗? 最佳答案 如
我尝试使用下面的代码将发现的设备的UUID存储到Array,然后在该阵列中选择UUID进行连接,但无法运行。 - (void)centralManager:(CBCentralManager *)ce
我正在研究一个通过蓝牙 LE 发送数据的 Android 应用程序。这里有两种方法让我感到困惑。有人可以解释一下这两种方法及其相互关系吗: private String localmessage =
我在使用 BluetoothLeScanner 的 startScan 方法时遇到了问题,找到了一个 BLE 设备,但是当我关闭 BLE 设备时,我的手机仍然显示此设备已打开!! 我尝试过使用: pr
我使用 StartLeScan 已经有一段时间了,扫描后返回的设备的名称从未被填充。我永远无法弄清楚为什么,我只是找回了 mac 地址。今天我从 OS BT 设置页面运行扫描,它只显示 MAC 地址,
在实现大量使用 Service 的 Android 应用程序方面,我不是很有经验,而且我在 SO 或 github 上找不到任何好的建议或示例来帮助我(或者只是谷歌搜索)所以我决定问我自己的问题。 当
开发用于蓝牙技术的移动应用程序能否用于蓝牙 LE 技术? 或者开发人员是否需要修改代码来处理蓝牙 LE(智能)信号、输入、输出等? 编辑 问这个问题的时候我想知道 如果我写一段代码,我可以在 BLE
我是一名优秀的程序员,十分优秀!