Is there any way to programmatically answer incoming calls in Android 7.0 without root privileges? I tried following way to pick up an incoming call.
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Class<?> c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
Object telephonyService = m.invoke(tm);
Class<?> telephonyServiceClass = Class.forName(telephonyService.getClass().getName());
Method endCallMethod = telephonyServiceClass.getDeclaredMethod("answerRingingCall");
endCallMethod.invoke(telephonyService);
There's a weird trick you can do with notification listeners, listen to all notifications by creating a service, whenever a call is coming it'll definitely show a notification to ask the user whether to pick up or not.
Create a service
Here we are assuming that the notification has an action with label as answer, thereby we are making a match and calling the corresponding intent related with it. In the launcher activity ask the permission for accessing notifications
Finally register the service for listening to notifications