BLE扫描的SCAN_FAILED_APPLICATION_REGISTRATION_FAILED解决方案? [英] Solution for BLE scan's SCAN_FAILED_APPLICATION_REGISTRATION_FAILED?

查看:692
本文介绍了BLE扫描的SCAN_FAILED_APPLICATION_REGISTRATION_FAILED解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Android应用扫描BLE设备,从某个点开始失败,并显示错误代码2( ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED ).我正在使用Nexus 9、5.0.1棒棒糖.

My Android app scans BLE devices, and from a certain point it start to fails with error code 2 (ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED). I'm using Nexus 9, 5.0.1 Lollipop.

即使我重新启动了该应用程序,该问题仍然存在,并且当我从设置"重新启动蓝牙服务时,我终于可以摆脱该问题.但是这个问题反复出现,而且我认为我的编码方式有误. BLE相关的API是新的,几乎没有信息.

This problem continued even after I relaunched the app, and when I restarted the Bluetooth service from Settings, I could finally get rid of the problem. But this problem is recurring, and I think I'm coding in a wrong way; BLE related APIs are new and there is few information.

有人知道该错误的一般解决方案,最好不需要重启蓝牙服务吗?即使此错误代码已记录在Android API参考中,我也不知道如何正确处理它.

Does anyone know a general solution for this error, preferably not requiring restart of the Bluetooth service? Even though this error code is documented in Android API reference, I don't know how to handle it properly.

推荐答案

出现错误

SCAN_FAILED_APPLICATION_REGISTRATION_FAILED

您应该禁用BluetoothAdapter

You should disable the BluetoothAdapter

BluetoothAdapter.getDefaultAdapter().disable();

禁用BluetoothAdapter,将触发事件STATE_TURNING_OFF.触发此事件后,尝试重新连接到BluetoothAdapter:

Disabling BluetoothAdapter, the event STATE_TURNING_OFF is fired. Once this event is fired, try to reconnect to the BluetoothAdapter:

case BluetoothAdapter.STATE_OFF:
  Log.d(TAG, "bluetooth adapter turned off");
  handler.postDelayed(new Runnable() {
    @Override
    public void run() {
        Log.d(TAG, "bluetooth adapter try to enable");
        BluetoothAdapter.getDefaultAdapter().enable();
    }}, 500);
  break;

这篇关于BLE扫描的SCAN_FAILED_APPLICATION_REGISTRATION_FAILED解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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