I know many developers ask the same question about how to accept incoming calls on button click.
I'm working on an application like this. https://play.google.com/store/apps/details?id=com.colorphone.smooth.dialer&hl=en
I searched a lot and successfully implement the feature where application can detect an incoming call ( by following this one How to detect incoming calls, in an Android device? ) and opens up an activity where user has two choice, whether to accept the incoming call or reject it. The problem the i can't accept/reject the incoming call programmatically. I search a lot but couldn't find the specific solution. If anybody could help me on how could i accept the incoming call programmatically that will be great.
May be you can try through {@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)} To get a TelecomManager object, and then call acceptRingingCall() method to answer or call endCall() method to reject call.
public class TelecomManager {
/**
* If there is a ringing incoming call, this method accepts the call on behalf of the user.
*
* If the incoming call is a video call, the call will be answered with the same video state as
* the incoming call requests. This means, for example, that an incoming call requesting
* {@link VideoProfile#STATE_BIDIRECTIONAL} will be answered, accepting that state.
*
* Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} or
* {@link android.Manifest.permission#ANSWER_PHONE_CALLS}
*/
//TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
// this method (clockwork & gearhead).
@RequiresPermission(anyOf =
{Manifest.permission.ANSWER_PHONE_CALLS, Manifest.permission.MODIFY_PHONE_STATE})
public void acceptRingingCall() {
try {
if (isServiceConnected()) {
getTelecomService().acceptRingingCall(mContext.getPackageName());
}
} catch (RemoteException e) {
Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
}
}
From the release of Marshmallow, runtime permissions are necessary to access user's phone and user's data.
Now, Coming to your question, To pickup call via grammatically you need 2 Permissions
Manifest.permission.ANSWER_PHONE_CALLS
and Manifest.permission.MODIFY_PHONE_STATE
but MODIFY_PHONE_STATE is Not for use by third-party applications .
Read this documentation
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.