1

I am working on an audio routing app which can direct audio between either headset and/or speaker of a phone. Is there any way I can programmatically stop headset detection?

EDIT: I am using a wired headset.

SoulRayder
  • 5,072
  • 6
  • 47
  • 93

1 Answers1

0

When you say "handset", do you mean "wired headset"? If so, there's an intent to detect whether or not one is being plugged or unplugged: ACTION_HEADSET_PLUG.

To check the status, you can use AudioManager.isWiredHeadsetOn(), although that may return false if there is also a bluetooth headset, and audio is routed to that instead.

Like in this manner:

final AudioManager audio =(AudioManager)getApplicationContext().getSystemService(AUDIO_SERVICE);
if(audio.isWiredHeadsetOn())
            {
                audio.setWiredHeadsetOn(false);
                audio.setSpeakerphoneOn(true);


            }

But before that

So, You might write this code in "AndroidManifest.xml"

<receiver android:name="com.juno.brheadset.HeadsetStateReceiver">
    <intent-filter>
        <action android:name="android.intent.action.HEADSET_PLUG"/>
    </intent-filter>
</receiver>-->

But, This doesn't work. When OS send this "HEADSET_PLUG" intent, OS set the flag "Intent.FLAG_RECEIVER_REGISTERED_ONLY" So, You should write the code like below in Activity or Service class instead of "AndroidManifest" things.

public class BRHeadsetActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    IntentFilter receiverFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    HeadsetStateReceiver receiver = new HeadsetStateReceiver();
    registerReceiver( receiver, receiverFilter );


}

In this way you can solve this problem.

Satyaki Mukherjee
  • 2,857
  • 1
  • 22
  • 26
  • This will detect whether headset is connected or not. I want to disable that headset detection mechanism itself. :) – SoulRayder Jan 08 '14 at 09:57
  • Please see this tutorial, it may help you http://stackoverflow.com/questions/13193873/how-to-detect-the-bt-headset-or-wired-headset-in-android – Satyaki Mukherjee Jan 08 '14 at 10:01