我想知道如何拦截来电并自动激活扬声器。我读过这个类是用com.android.internal.telephony但我找不到propre文档。谢谢你的帮助。
答案 0 :(得分:2)
以下是拦截来电的代码
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;
}
};
};
激活扬声器
AudioManager POAudioService = (AudioManager) POContext.getContext().getSystemService(Context.AUDIO_SERVICE);
POAudioService.setSpeakerphoneOn(true);
答案 1 :(得分:1)
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);
}
};
答案 2 :(得分:1)
所需权利: uses-permission android:name =" android.permission.MODIFY_AUDIO_SETTINGS"