This worked for me.Put this code in your broadcast reciever for action "android.intent.action.PHONE_STATE" .Your phone needs to be rooted.Generate an apk file of ur app and put it into /system/priv-apps/ .Works for Android v 5.0 i.e lollipop.
   final String LOG_TAG = "TelephonyAnswer";
    TelephonyManager tm = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    try {
        if (tm == null) {
            // this will be easier for debugging later on
            throw new NullPointerException("tm == null");
        }
        // do reflection magic
        tm.getClass().getMethod("answerRingingCall").invoke(tm);
    } catch (Exception e) {
    }
Do not forget to add permission in ur manifest.
 <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
 <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
if modify_phone_state doesnt work explicitly ask for one by using this code
 ActivityCompat.requestPermissions(MainActivity.this,
                new String[]{Manifest.permission.MODIFY_PHONE_STATE},
                1);
and overide method
@Override
public void onRequestPermissionsResult(int requestCode,
                                       String permissions[], int[] grantResults) {
    switch (requestCode) {
        case 1: {
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            } else {
                Toast.makeText(MainActivity.this, "Permission denied to pick call", Toast.LENGTH_SHORT).show();
            }
            return;
        }
    }
}