hey..i plan to add a function to my app which will auto switch on the loudspeaker when the user received phone call..
here are part of my codes:
case TelephonyManager.CALL_STATE_OFFHOOK:
//CALL_STATE_开发者_Python百科OFFHOOK;
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
am.setMode(AudioManager.MODE_IN_CALL);
am.setSpeakerphoneOn(true);
boolean check = am.isSpeakerphoneOn();
Toast.makeText(Speaker.this, "LoudSpeaker On: "+ check,Toast.LENGTH_LONG).show();
and i already added the permission for MODIFY_AUDIO_SETTINGS in the manifest..however..the speakerphone didnt manage to turn on..can anyone kindly give a helping hand on this problem..thanks in advance..by the way..this app was implement in android 2.1
try to hold 500 ms before turning it on ..
so it will be something like :
case TelephonyManager.CALL_STATE_OFFHOOK:
// CALL_STATE_OFFHOOK;
try {
Thread.sleep(500); // Delay 0,5 seconds to handle better turning on
// loudspeaker
} catch (InterruptedException e) {
}
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
am.setMode(AudioManager.MODE_IN_CALL);
am.setSpeakerphoneOn(true);
boolean check = am.isSpeakerphoneOn();
Toast.makeText(Speaker.this, "LoudSpeaker On: " + check,
Toast.LENGTH_LONG).show();
btw I have Xperia 4.1.2 and your initial code is working without any issue ..
精彩评论