Turning bluetooth on, gives back wrong request code in onActivityResult
android, bluetooth
Solution
Damn. Should have used:
getSupportActivity().startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
wrong requestCode in onActivityResult
http://blog.tgrigsby.com/2012/04/18/android-fragment-frustration.aspx
Problem
This is my code, for turning on the bluetooth: ``` Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); ``` Also: ``` public static final int REQUEST_ENABLE_BT = 9; ``` This is my onActivityResult: ``` @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_ENABLE_BT: if (resultCode == Activity.RESULT_OK) { bluetoothSetupDone(); } else { // User did not enable Bluetooth or an error occurred } break; default: super.onActivityResult(requestCode, resultCode, data); break; } } ``` The result code is correct, but the request code is not. Even if the user presses no, or yes on the popup dialog for turning on bluetooth. The value of the requestCode variable in the onActivityResult is some random number (196617), but it should be 9.