7

내 안드로이드 앱이 BLE 장치를 검색하고 특정 지점에서 오류 코드 2 (ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED)로 실패하기 시작합니다. Nexus 9 5.0.1 Lollipop을 사용하고 있습니다.BLE 스캔의 SCAN_FAILED_APPLICATION_REGISTRATION_FAILED 솔루션?

이 문제는 앱을 다시 시작한 후에도 계속 발생하며 설정에서 블루투스 서비스를 다시 시작하면 마침내 문제를 해결할 수 있습니다. 그러나이 문제는 반복적으로 발생하며 잘못된 방식으로 코딩하고 있다고 생각합니다. BLE 관련 API는 새롭고 정보가 거의 없습니다.

누구든지이 오류에 대한 일반적인 해결책을 알고 있습니까? Bluetooth 서비스를 다시 시작하지 않아도됩니다. 이 오류 코드는 Android API 참조 문서에 설명되어 있지만 올바르게 처리하는 방법을 알지 못합니다. 당신은 당신은 BluetoothAdapter를 비활성화 BluetoothAdapter

BluetoothAdapter.getDefaultAdapter().disable(); 

를 비활성화해야 오류

SCAN_FAILED_APPLICATION_REGISTRATION_FAILED 

있어

+0

아니요, 제 코드에도 비슷한 문제가 있습니다. 지금까지 운 없음 – Amit

답변

0

는 이벤트 STATE_TURNING_OFF가 발생합니다. 이 이벤트가 발생하면 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

BT 어댑터의 성공적인 초기화 만 수행해야합니다. 이 준비가 텐트 필터 생성 할 수 있는지 :

val filter = IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED) 

방송 수신기 (당신은 어댑터가 준비 경우에만 작업을 수행 할 것) :

val broadcastReceiver = object: BroadcastReceiver() { 
      override fun onReceive(context: Context, intent: Intent?) { 
       val action = intent?.action 
       if (action != null && action == BluetoothAdapter.ACTION_STATE_CHANGED) { 
        val state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR) 
        when (state) { 
         BluetoothAdapter.STATE_ON -> { 
          if (bluetoothAdapter.isEnabled) { 
           //perform your task here 
          } 
         } 
         BluetoothAdapter.STATE_OFF -> {} 
        } 
       } 
      } 
     } 

후 등록 수신기

registerReceiver(broadcastReceiver, filter) 

및 재발행 어댑터 ()이 부분은 수표) :

bluetoothAdapter.disable() 
bluetoothAdapter.enable() 

완료!