How to check and redirect audio between wired headset and speaker phone?

北城余情 提交于 2019-12-02 02:22:48
Digit

you have to register a receiver for ACTION_HEADSET_PLUG intent and make a receiver class to catch that broadcast from that you can implement your own logic please check this

SoulRayder

Finally managed to solve my own problem using this work around (as suggested by @noelicus):

How to mute audio in headset but let it play on speaker programmatically?

Posted for reference to others who might get stuck like me. :)

AudioManager mAudioMgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

        mVolumeButton = (Button)findViewById(R.id.btn_Volume);
        mVolumeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mAudioMgr.isWiredHeadsetOn()){

                    mAudioMgr.setWiredHeadsetOn(false);
                    mAudioMgr.setSpeakerphoneOn(true);
                    mAudioMgr.setMode(AudioManager.MODE_IN_COMMUNICATION);

                    Toast.makeText(getApplicationContext(), "SpeakerPhone On", Toast.LENGTH_LONG).show();
                }else{
                    mAudioMgr.setMode(AudioManager.MODE_IN_COMMUNICATION);
                    mAudioMgr.setSpeakerphoneOn(false);
                    mAudioMgr.setWiredHeadsetOn(true);
                    Toast.makeText(getApplicationContext(), "Wired Headset On", Toast.LENGTH_LONG).show();
                }
            }
        });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!