Android 如何查看拨打的号码是否占线或无人接听?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11416374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:20:45  来源:igfitidea点击:

How to check if the dialed number is busy or is not answered?

androidphone-calltelephonytelephonymanager

提问by Zardaloop

I have used the following code to dial a number:

我已使用以下代码拨打号码:

DataBaseHelper db;
db=new DataBaseHelper(PanicService.this);
try {

    db.createDataBase();

    } catch (IOException ioe) {

    throw new Error("Unable to create database");

    }

Map<String, String > map= db.TelephoneList();
String[] numbers = new String[]{"number1","number2","number3","number4","number5"};


Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+map.get(numbers[0])));
callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(callIntent);

which is working fine. Now I need to know if the dialled number is busy or is unanswered, and it it is dial the next number in the list. I am just wondering if there is anyway to detect the state of the call?

这是工作正常。现在我需要知道拨打的号码是忙还是无人接听,它是拨打列表中的下一个号码。我只是想知道是否有办法检测通话状态?

I have checked this URL http://developer.android.com/reference/android/telephony/TelephonyManager.htmlbut I can't find anything around that concept apart from CALL_STATE_OFFHOOK which is not really what I want.

我已经检查了这个 URL http://developer.android.com/reference/android/telephony/TelephonyManager.html但除了 CALL_STATE_OFFHOOK 之外我找不到任何关于这个概念的东西,这并不是我真正想要的。

采纳答案by Michael Hampton

You cannot determine whether an outgoing call on the mobile network was answered, because this information isn't provided to the handset by the mobile network, and even if it was, Android does not provide a way to receive it.

您无法确定移动网络上的拨出电话是否已接听,因为此信息不会由移动网络提供给手机,即使提供,Android 也不提供接收它的方法。

While it's possible to determine whether an outgoing Internet (SIP) call was answered, Android doesn't currently (as of Jelly Bean) provide a way of doing this that I can find from a quick look at the source code.

虽然可以确定外发 Internet (SIP) 呼叫是否得到应答,但 Android 目前(从 Jelly Bean 开始)没有提供一种方法,我可以通过快速查看源代码找到这种方法。