我知道许多开发人员都会问有关如何在按钮单击时接受传入呼叫的相同问题。
我正在开发这样的应用程序。
https://play.google.com/store/apps/details?id=com.colorphone.smooth.dialer&hl=en
我进行了很多搜索并成功实现了该功能,在该功能中,应用程序可以检测到来电(通过遵循此How to detect incoming calls, in an Android device?)并打开一个活动,用户可以选择接受还是拒绝来电两种选择。我无法以编程方式接受/拒绝来电的问题。我搜索了很多,但是找不到具体的解决方案。如果有人可以帮助我如何以编程方式接听来电,那将很棒。
最佳答案
也许你可以尝试
通过{@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)}
要获取TelecomManager对象,然后调用acceptRingingCall()方法来应答或调用endCall()方法来拒绝呼叫。
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);
}
}
关于android - 接听Android Studio的来电,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49745520/