Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
812 views
in Technique[技术] by (71.8m points)

bluetooth lowenergy - Solution for BLE scan's SCAN_FAILED_APPLICATION_REGISTRATION_FAILED?

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.

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When you got the error

SCAN_FAILED_APPLICATION_REGISTRATION_FAILED

You should disable the BluetoothAdapter

BluetoothAdapter.getDefaultAdapter().disable();

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...