0

I've tried a bunch of alternatives for auto answer incoming call.

1) Tried using Private API's (End call is working answer call doesn't)

2) Using SendOrderedBroadcast and various other methods that are mentioned in this post How can incoming calls be answered programmatically in Android 5.0 (Lollipop)?

If i use private api it is throwing SecurityException (Asking for the MODIFY_DEVICE_STATE permission) and if i use methods in the above post it is showing the below warnings

"Cancelling event due to no window focus: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_HEADSETHOOK, scanCode=0, metaState=0, flags=0x20, repeatCount=0, eventTime=7550277, downTime=7550277, deviceId=-1, source=0x101 }"

Please help me if there is any workaround for this issue, im using Android Version 23.

Thanks in advance..

Community
  • 1
  • 1
loop
  • 31
  • 1
  • 7

2 Answers2

0

There will be some extra work to be done for this to work, to answer an incoming call.

1) You need to have access for "DRAW OVER OTHER APPS" i.e. Screen Overlay permission, this will also include android.permission.SYSTEM_ALERT_WINDOW permission in the manifest.

2) You need to implement a Broadcast Receiver to check for the incoming call.

3) When an CALL_STATE_RINGING is detected, start a new activity that draws over other applications, using WindowsManager. Also, set a wakelock in this activity to make the phone awake if in lockscreen mode.

4) Also use this activity for using answer call methods, this will work as now your application is on the top and in forground.

5) Kill this activity and if needed open your project from this activity and then kill this activity.

New solution is here, look on this question:

Programmatically accept call in Nougat

Vishal Sharma
  • 616
  • 1
  • 6
  • 21
0

I've solved this by using AnswerRingingCall function in TelephonyManager, which will be triggered by a phone state listener (TelephonyManager.CALL_STATE_RINGING), when you use this method it actually throws a Security Exception (asking for MODIFY_STATE Permission), but this will be bypassed in Rooted devices by pushing the apk to /system/priv-app

loop
  • 31
  • 1
  • 7