How to fix Android BLE SCAN_FAILED_APPLICATION_REGISTRATION_FAILED error?

前端 未结 5 2011
北荒
北荒 2021-02-07 03:28

Most of times it works great but sometimes i\'m having this error while trying to discover BLE devices:

02-12 18:00:41.952  16178-16339/com.icrealtime.allie W/Bl         


        
相关标签:
5条回答
  • 2021-02-07 04:07

    you need to add following permission in the manifest:

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-feature android:name="android.hardware.location.network"/>
    

    If not the coarse location will not be able to access network and so the LeScan break up

    0 讨论(0)
  • 2021-02-07 04:12

    Make sure you close the GattConnection if you disconnect and/or reconnect. Just disposing of the object doesn’t release underlying resources and you will soon reach a limit as there, to my understanding, are no more than 32 possible simultaneous clients across all apps.

    0 讨论(0)
  • 2021-02-07 04:16

    A possible workaround it might be to disable/enable the blueetooth programmatically. 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;
    
    0 讨论(0)
  • 2021-02-07 04:20

    I had the same issue and this worked for me. Might look like a silly fix but worked lol.

    After adding the required Bluetooth and Location permission requirements in your manifest file...

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION_LOCATION" />
    

    You must turn on the FINE LOCATION or COARSE LOCATION permissions for the app. You could do this manually from the app settings on the device or add this bit of code to your onCreate() method.

    if (ContextCompat.checkSelfPermission(this.getApplicationContext(),
                    android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            } else {
                ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
                        REQUEST_LOCATION_ENABLE_CODE);
            }
    

    You'll also need to define int REQUEST_LOCATION_ENABLE_CODE as 1.

    0 讨论(0)
  • 2021-02-07 04:32

    Ideally, please look into the phone's location services support (Android 6+ BLE services require it be on for proper functionality). We've seen this issue on other occasions with Cordova plugins. Turn on location services (or check that these are turned on).

    0 讨论(0)
提交回复
热议问题