如何接受呼叫通过点击按钮进入的? [英] How to accept an incoming call by clicking a button?

查看:163
本文介绍了如何接受呼叫通过点击按钮进入的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,所有!

我想实现我自己的电话呼叫处理用户界面。

I'm trying to implement my own phone call handling UI.

我想要做的是,如果有电话打进来,输入电话号码和图片的显示,并且,如果我preSS按钮,来电将被接受/应答。

What I want to do is, if a call comes in, the incoming telephone number and a picture are displayed, and, if I press a button, the incoming call will be accepted/answered.

的相关codeS是:

 @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    answerButton = (Button) findViewById(R.id.pickup);
    answerButton.setOnClickListener(new OnClickListener() {
        public void onClick(final View v) {
            Intent intent = new Intent("android.intent.action.ANSWER");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);          
        }
    });

可悲的是,code不起作用。首先,抛出一个异常,如果我preSS我的回答按钮:

Sadly, the code does not work. At first, an exception is thrown if I press my answer button:

  ActivityNotFoundException: No Activity found to handle Intent {    act=android.intent.action.ANSWER

然后我说在AndroidManifest.xml中的条目:

Then I added an entry in the AndroidManifest.xml:

<uses-permission android:name="android.permission.CALL_PHONE" />

我再次运行应用程序,存在了也不例外。不过,我怀疑来电是不是真的被接受。因为如果preSS的Andr​​oid的屏幕接听键(绿色按钮),来电被接受,并在通话图标绿色也显示在模拟器的屏幕的左上角,而我的应用程序没有。

I run the app again, there is no exception anymore. However, I doubt the incoming call is not really accepted. Because if the press the Android's screen answer button (green button), the incoming call is accepted and a green in call icon is also displayed on the upper left corner of the emulator screen, while my app doesn't.

我也看到了手机应用程序的源$ C ​​$ c在Android的源代码。有方法,如acceptCall()在电话类。但C $ CS这些$似乎对我来说很难使用,因为有很多的进口报关,在code,如:

I also read the Phone app's source code in android source. There is method such as acceptCall() in the Phone class. But these codes seem difficult for me to use, because there are many imports declaration in the code, such as :

import com.android.internal.telephony.Call;
import com.android.internal.telephony.CallStateException;
import com.android.internal.telephony.CallerInfo;
import com.android.internal.telephony.CallerInfoAsyncQuery;
import com.android.internal.telephony.Connection;
import com.android.internal.telephony.MmiCode;
import com.android.internal.telephony.Phone;

而且,如果我在code增加这些进口,就会有太多的错误,如:进口com.android.internal.telephony解决不了的

And, if I add these imports in my code, there will be too many errors, such as : "The import com.android.internal.telephony cannot be resolved"

什么是我的问题,正确的和简单的方式?

What is the right and simple way for my problem?

在此先感谢!

推荐答案

这样做的目的 android.intent.action.ANSWER 不知何故没有按预期工作。有一种变通方法通过模拟蓝牙按钮接听来电。你可以看到从自动应答项目的例子。

The intent android.intent.action.ANSWER is somehow not working as expected. There is a workaround by emulating the bluetooth button to answer the incoming call. You can see an example from auto-answer project.

这篇关于如何接受呼叫通过点击按钮进入的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆