+ } break;
+
+ case BluetoothAdapter.STATE_ON:
+ case BluetoothAdapter.STATE_TURNING_ON: {
+ Intent intent = new Intent(this, RequestPermissionHelperActivity.class);
+ intent.putExtra(RequestPermissionHelperActivity.EXTRA_APP_LABEL, mAppLabel);
+ intent.setAction(RequestPermissionHelperActivity
+ .ACTION_INTERNAL_REQUEST_BT_OFF);
+
+ startActivityForResult(intent, 0);
+ } break;
+
+ default: {
+ Log.e(TAG, "Unknown adapter state: " + btState);
+ cancelAndFinish();
+ } break;
+ }
+ } else {
+ switch (btState) {
+ case BluetoothAdapter.STATE_OFF:
+ case BluetoothAdapter.STATE_TURNING_OFF:
+ case BluetoothAdapter.STATE_TURNING_ON: {
+ /*
+ * Strictly speaking STATE_TURNING_ON belong with STATE_ON;
+ * however, BT may not be ready when the user clicks yes and we
+ * would fail to turn on discovery mode. By kicking this to the
+ * RequestPermissionHelperActivity, this class will handle that
+ * case via the broadcast receiver.
+ */
+
+ /*
+ * Start the helper activity to:
+ * 1) ask the user about enabling bt AND discovery
+ * 2) enable BT upon confirmation
+ */
+ Intent intent = new Intent(this, RequestPermissionHelperActivity.class);
+ intent.setAction(RequestPermissionHelperActivity.ACTION_INTERNAL_REQUEST_BT_ON);
+ intent.putExtra(RequestPermissionHelperActivity.EXTRA_APP_LABEL, mAppLabel);
+ if (mRequest == REQUEST_ENABLE_DISCOVERABLE) {
+ intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, mTimeout);
+ }
+ startActivityForResult(intent, 0);
+ } break;
+
+ case BluetoothAdapter.STATE_ON: {
+ if (mRequest == REQUEST_ENABLE) {
+ // Nothing to do. Already enabled.
+ proceedAndFinish();
+ } else {
+ // Ask the user about enabling discovery mode
+ createDialog();
+ }
+ } break;
+
+ default: {
+ Log.e(TAG, "Unknown adapter state: " + btState);
+ cancelAndFinish();
+ } break;
+ }