- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在尝试使用函数 BluatoothLeScanner.startScan 而不是已弃用的 BluetoothAdapter.startLeScan。昨天我将我的 Nexus 5 更新到了 Android 6.0,从那一刻起我的应用程序不再工作了。我首先添加了所需的首选项ACCESS_COARSE_LOCATION,如下所示,https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-hardware-id .然后我添加了这里描述的权限:https://developer.android.com/training/permissions/requesting.html .但最后它似乎不起作用,它没有发回 ble 设备。
这是我的代码:
list
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.stm.sensitronapp">
<uses-sdk android:maxSdkVersion="23"/>
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>`
DeviceScanActivity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
if (ContextCompat.checkSelfPermission(this,Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED){
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_COARSE_LOCATION)) {
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
MY_PERMISSIONS_REQUEST_ACCESS_COARSE);
}
}
// Device scan callback.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (ContextCompat.checkSelfPermission(this,Manifest.permission.ACCESS_COARSE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
mScanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
mLeDeviceListAdapter.addDevice(result.getDevice());
mLeDeviceListAdapter.notifyDataSetChanged();
}
};
}
}
}
final BluetoothManager bluetoothManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
mSwipeRefreshLayout.setRefreshing(true);
mLeDeviceListAdapter.clear();
mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
if(ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION ) == PackageManager.PERMISSION_GRANTED) {
mBluetoothLeScanner.startScan(mScanCallback);
}
}
编辑:为了解决这个问题,我只打开了 GPS。在 this way 中以编程方式很容易做到这一点.
最佳答案
如果授予权限,请尝试:打开 GPS。
关于android - 使用 Android 6.0 的 BluetoothLeScanner.startScan 无法发现设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33013818/
我的蓝牙应用程序有问题。当我在启动应用程序之前启用蓝牙时,一切正常。但是当我不这样做时,我的应用程序会通过 turnOn 方法请求启用蓝牙的权限。但是当我按下我的 onScan 按钮时,我收到一条错误
我对 Android 和 Kotlin 很陌生,所以我可能会遇到一些非常简单的错误,但据我所知,当我调用 BluetoothLeScanner.startScan() 时,我创建的 ScanCallb
所以我尝试实现一个 BLE 扫描器。唯一的问题是我无法让它给我任何输出。这是我的代码: MainActivity.java public class MainActivity extends
我正在尝试实现一个应用程序,当拿着手机的人移动时启动 BLE 扫描,如果超过 10 秒没有移动则自动关闭,而移动检测工作正常 BLEscanner 出了点问题这是代码 import android.a
我想用 BluetoothLeAdvertiser 通过 android 传输 iBluetooth来自 android.bluetooth.le 的类(class).但我似乎无法设置某些制造商规范数
我正在 android 上使用 BLE 实现一个简单的广告 + 扫描功能,由于某种原因,我收到了很多通过同一设备的 onScanResult 回调调用。 用于广告: //Advertise setti
我正在尝试在一个简单的安卓应用程序中实现一个 BLE 扫描仪。我一直在关注: startLeScan replacement to current api和 https://developer.and
我正在使用我自己的 BLE 设备。在监听这些设备时,我想使用 ScanFilter,所以我只得到我感兴趣的设备。我现在的解决方案是在回调内部进行过滤,但如果可以进行这种过滤会更好更早并且根据规范应该是
我正在研究低蓝牙室内定位系统,并且一直在使用 https://github.com/inthepocket/ibeacon-scanner-android用于计算我的移动设备和多个 BLE 信标之间的
由于我在 Android Lollipop 上遇到蓝牙问题,我尝试更改扫描仪方法。 所以我尝试使用新包。 在以前的版本中,我调用了 startScan(mLeScanCallback) 并且一切正常,
我有一个 Android 应用用例,需要“连续”扫描 BLE 设备。 仅此一项要求就可能让我成为受虐狂,我猜这会让 Android 成为我的施虐狂。 我知道[我相信]仍未正式记录“30 秒内扫描不超过
我有一个 Android 应用用例,需要“连续”扫描 BLE 设备。 仅此一项要求就可能让我成为受虐狂,我猜这会让 Android 成为我的施虐狂。 我知道[我相信]仍未正式记录“30 秒内扫描不超过
在 Android 6.0 版本(API 23)中,我注意到 BluetoothLeScanner.startScan() 需要新的权限; ACCESS_COARSE_LOCATION 和/或 ACC
我正在尝试使用函数 BluatoothLeScanner.startScan 而不是已弃用的 BluetoothAdapter.startLeScan。昨天我将我的 Nexus 5 更新到了 Andr
我是一名优秀的程序员,十分优秀!