I would like to know how to intercept incoming calls and activate loud speaker automatically. I read this class is used com.android.internal.telephony but I could not find propre documentation. Thanks for your help.
Asked
Active
Viewed 1,003 times
3 Answers
2
Here is code for intercepting incoming calls
PhoneStateListener mListner = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_OFFHOOK:
// TODO
break;
case TelephonyManager.CALL_STATE_RINGING:
// TODO
break;
default:
break;
}
};
};
Activate the loud speaker
AudioManager POAudioService = (AudioManager) POContext.getContext().getSystemService(Context.AUDIO_SERVICE);
POAudioService.setSpeakerphoneOn(true);

Dinesh Prajapati
- 9,274
- 5
- 30
- 47
-
In the above code, what is POContext? Is it a class you have created? I have tried similar code to turn on speaker using a BroadCastReceiver, but it does not work. Can you answer this question: http://stackoverflow.com/questions/8617381/turn-on-speakerphone-whenever-an-outgoing-call-is-made I have given all necessary permissions in Manifest file. – AllSolutions Jan 12 '12 at 16:34
-
POContext is normal context..i have defined it as my own variable – Dinesh Prajapati Jan 21 '12 at 05:49
2
private TelephonyManager telManager;
//on create method
telManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if (telManager != null) {
telManager.listen(phoneStateListener,
PhoneStateListener.LISTEN_CALL_STATE);
}
PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
onCall = true;
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
onCall = false;
} else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
onCall = true;
//activate your loud speaker
}
super.onCallStateChanged(state, incomingNumber);
}
};

Hades
- 3,916
- 3
- 34
- 74
1
Required rights: uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"

Michalsx
- 3,446
- 5
- 33
- 46