I have a problem checking the result of the callback, when I call onActivityResult () to get the result if the user allowed or canceled the activation of bluetooth, the program does not wait for the result of the user's decision.
I need you to wait for the answer so that I can ask in the If correctly.
public void iniciarBluetooth(){
if(localBT == null){
Log.d(TAG, "iniciarBlueetooth: El dispositivo no cuenta con blueetoth integrado");
}else if(!localBT.isEnabled()){
Log.d(TAG, "iniciarBlueetooth: iniciando bluetooth");
Intent iniciarBluetoothIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(iniciarBluetoothIntent, REQUEST_ENABLE_BT);
int resultado = 0;
onActivityResult(REQUEST_ENABLE_BT, resultado, iniciarBluetoothIntent);
if(resultado == RESULT_OK) {
Log.d(TAG, "iniciarBlueetooth: Se encendera el bluetooth");
switchBT.setText(getString(R.string.apagarBT));
}else
Log.d(TAG, "iniciarBlueetooth: Se cancelo la solicitud de encendido bluetooth");
}else if(localBT.isEnabled()){
Log.d(TAG, "iniciarBlueetooth: apagando bluetooth");
localBT.disable();
switchBT.setText(getString(R.string.encenderBT));
}
}
Logcat response
/com.example.refer.bluetooth D/MainActivity: iniciarBlueetooth: iniciando bluetooth
//No espera el resultado del callback y comprueba con el valor de inicializacion del Int resultado
/com.example.refer.bluetooth D/MainActivity: iniciarBlueetooth: Se cancelo la solicitud de encendido bluetooth