Example of hands free switching enabled by android

  • 2020-05-27 07:11:27
  • OfStack

The following code implements the hands-free on and off functions of android

The permissions you need to add


<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>


/**
 *  hands-free 
 * 
 * @param context
 */
private void toggleSpeaker(Context context)
{
    AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    am.setMode(AudioManager.MODE_IN_CALL);
    am.setSpeakerphoneOn(!am.isSpeakerphoneOn());
}


Related articles: