Call auto answer android
Call
anto answer android is a great feature to attend the call without
click any buttons.Its very useful when the user is in drive or hands
busy with other works.
//study
about call logs
Steps:
1.your have to check the phone is ringing or not.
1.your have to check the phone is ringing or not.
TelephonyManager
tm = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
if
(tm.getCallState() != TelephonyManager.CALL_STATE_RINGING) {
return;
}
2)if
phone is in ringing state answer the call.
//
Simulate a press of the headset
button to pick up the call
Intent
buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
buttonDown.putExtra(Intent.EXTRA_KEY_EVENT,
new KeyEvent(KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_HEADSETHOOK));
context.sendOrderedBroadcast(buttonDown,
"android.permission.CALL_PRIVILEGED");
//
froyo
and beyond trigger on buttonUp instead of buttonDown
Intent
buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
buttonUp.putExtra(Intent.EXTRA_KEY_EVENT,
new KeyEvent(KeyEvent.ACTION_UP,
KeyEvent.KEYCODE_HEADSETHOOK));
context.sendOrderedBroadcast(buttonUp,
"android.permission.CALL_PRIVILEGED");
Answer
the phone calls using AIDL
//
Set up communication with the telephony service
TelephonyManager
tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
Class
c = Class.forName(tm.getClass().getName());
Method
m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony
telephonyService;
telephonyService
= (ITelephony)m.invoke(tm);
//
Silence the ringer and answer the call!
telephonyService.silenceRinger();
//Answer
the ringing call
telephonyService.answerRingingCall();
3)optional,If
you want to set callautoanswer delay use,
try
{
//set
thread for delay auto call answer interval .
//here
I set 2 seconds.
Thread.sleep(Integer.parseInt(prefs.getString("delay",
"2")) * 1000);
}
catch (InterruptedException e) {
//
We don't really care
}
4)optional,To
enable loudspeaker use this code,
AudioManager
audioManager = (AudioManager)
context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setSpeakerphoneOn(true);
No comments:
Post a Comment