Android Loud speaker and call interception
I would like to know how开发者_如何学Python 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.
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);
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);
}
};
Required rights: uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"
精彩评论