title: Unable to record Audio via Bluetooth in Android
body: <p>I am writing an android app for Recording Audio from Blue tooth, but I Unable to record Audio via Blue tooth in Android.
  You can see below the code</p>
  
  <pre><code>AudioManager am;
  am = (AudioManager) getSystemService(AUDIO_SERVICE);
       am.setMode(AudioManager.MODE_IN_CALL);
       am.startBluetoothSco();
       am.setBluetoothScoOn(true);
      Intent intent = getIntent();
   if (intent.getBooleanExtra("privacy", false)) {
          showServerPrompt(true);
          return;
      }
  
      // If the Ringdroid media select activity was launched via a
      // GET_CONTENT intent, then we shouldn't display a "saved"
      // message when the user saves, we should just return whatever
      // they create.
      mWasGetContentIntent = intent.getBooleanExtra(
          "was_get_content_intent", false);
  
      mFilename = intent.getData().toString();
  
      mSoundFile = null;
      mKeyDown = false;
  
      if (mFilename.equals("record")) {
          try {Intent recordIntent = new Intent(
                  MediaStore.Audio.Media.RECORD_SOUND_ACTION);
              startActivityForResult(recordIntent, REQUEST_CODE_RECORD);
  
          } catch (Exception e) {
              showFinalAlert(e, R.string.record_error);
          }
  
      }
  
      mHandler = new Handler();
  
      loadGui();
  
      mHandler.postDelayed(mTimerRunnable, 100);
  
      if (!mFilename.equals("record")) {
          loadFromFile();
      }
  }
  </code></pre>
  
  <p>This works well when using the phone in a normal fashion. However, it does not detect the presence of a bluetooth headset and still uses the phone's own microphone even when the headset is plugged in.</p>