简体   繁体   English

检测电话开始拨打电话的时间

[英]Detect the time when a phone starts ringing for outgoing calls

How do detect the time when a phone starts ringing for outgoing calls. 如何检测电话开始拨打电话的时间。 I am developing an Application in which I am trying to make a call programatically and when call is connected (ringing). 我正在开发一个应用程序,我正在尝试以编程方式进行呼叫以及何时连接呼叫(振铃)。 I want get back some response(Like connected). 我想要回复一些回复(比如连接)。 I am trying below code, its able to make call but don't know how to get response. 我正在尝试下面的代码,它能够拨打电话,但不知道如何获得响应。

Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"mobile no.")); 
             startActivity(callIntent);

Thanks in advance for your time and consideration. 提前感谢您的时间和考虑。

Edit : When outgoing call is connect (Ringing state) then i want get back a notification. 编辑:当拨出电话连接(振铃状态),然后我想收到通知。 like a toast or anything else which is relevant. 像吐司或任何其他相关的东西。 is it possible? 可能吗?

You will have to use a BroadcastReceiver to listen for the call event and then handle it when it gets fired. 您必须使用BroadcastReceiver来侦听调用事件,然后在触发时处理它。 Here is a nice tutorial I found on Google. 这是我在Google上找到的一个很好的教程。

http://looksok.wordpress.com/2013/04/13/android-broadcastreceiver-tutorial-detect-outgoing-phone-call-event/ http://looksok.wordpress.com/2013/04/13/android-broadcastreceiver-tutorial-detect-outgoing-phone-call-event/

I know its been a while but i hope to be helpful for someone still looking for a solution! 我知道它已经有一段时间但我希望对仍在寻找解决方案的人有所帮助!

I recently had to work on a similar project where i needed to capture the ringing state of an outgoing call and the only way i could find was using the hidden Api of native dial-up App. 我最近不得不在一个类似的项目上工作,我需要捕获拨出呼叫的振铃状态,我能找到的唯一方法是使用本机拨号应用程序的隐藏Api。 This would only be possible for android > 5.0 because of the api changes. 这仅适用于android> 5.0,因为api更改。 This was tested on Android 5.0.1, and worked like a charm. 这是在Android 5.0.1上测试过的,并且像魅力一样。 (ps you would need a rooted device for it to work, because you need to install your app as a System application (google how!) which will then be able to detect the outgoing call states). (ps你需要一个有根设备才能工作,因为你需要将你的应用程序安装为系统应用程序(谷歌如何!),然后才能检测到拨出呼叫状态)。

For the record, PhoneStateListener doesn't work for detecting the outgoing call states as mentioned in many posts. 对于记录,PhoneStateListener不能用于检测许多帖子中提到的传出呼叫状态。

First, add this permission in the manifest file, 首先,在清单文件中添加此权限,

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

Then define you broadcastreceiver, (here is a sample code!) 然后定义你broadcastreceiver,(这是一个示例代码!)

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;

public class MyBroadcastReceiver extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context, final Intent intent)
    {
        switch (intent.getIntExtra("foreground_state", -2)) {
            case 0: //  PreciseCallState.PRECISE_CALL_STATE_IDLE:
                System.out.println("IDLE");
                break;
            case 3: //  PreciseCallState.PRECISE_CALL_STATE_DIALING:
                System.out.println("DIALING");
                break;
            case 4: //  PreciseCallState.PRECISE_CALL_STATE_ALERTING:
                System.out.println("ALERTING");
                break;
            case 1: //  PreciseCallState.PRECISE_CALL_STATE_ACTIVE:
                System.out.println("ACTIVE");
                break;
        }

    }
} 

I replaced some of the constants with their values because I saw a lot of confusion among the folks unfamiliar with the concept of reflection (for ease). 我用它们的值替换了一些常量,因为我看到很多人不熟悉反射概念(为了方便)。 Alerting is basically the state when receiver is actually ringing! 警报基本上是接收器实际响铃时的状态! and that does not include the call setup time! 这不包括通话设置时间! so you can get the time in that case statement by using, 所以你可以通过使用,获得该案例陈述中的时间,

System.currentTimeMillis();

or some other format you would prefer! 或者你想要的其他格式!

It's impossible to detect by regular non-system application - no Android API. 通过常规的非系统应用程序检测是不可能的 - 没有Android API。 I could not find a way, I was googling the solution within very long time :-( 我找不到方法,我在很长一段时间内谷歌搜索解决方案:-(

There is NO way (sadly, because I need it) to detect the time of an outgoing call starts ringing. 没有办法 (遗憾的是,因为我需要它)来检测拨出电话开始振铃的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM