我如何获得在android手机一呼出的状态呢? [英] How do I get state of a outgoing call in android phone?

查看:188
本文介绍了我如何获得在android手机一呼出的状态呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在班上TelephonyManager注意到有CALL_STATE_IDLE,CALL_STATE_OFFHOOK和CALL_STATE_RINGING。他们似乎是用于传入呼叫

I noticed in the class TelephonyManager there are CALL_STATE_IDLE, CALL_STATE_OFFHOOK and CALL_STATE_RINGING. They seem to be used for incoming calls.

我真正想要做的是被通知时传出调用时,收到或超时。那怎么办?

What I actually want to do is to be notified when an outgoing call is made, is received, or timed out. How to do that?

推荐答案

我不知道你是否能检测定时呼叫,但区分当呼叫开始是可能的。

I don't know if you can detect a timed call, but differentiate when the call started is possible.

您可以像这样,在CALL_STATE_IDLE:

You can do it like this, in the CALL_STATE_IDLE:

Uri allCalls = Uri.parse("content://call_log/calls");
String lastMinute = String.valueOf(new Date().getTime() - DAY_IN_MILISECONDS); 
//before the call started
Cursor c = app.getContentResolver().query(allCalls, null, Calls.DATE + " > " 
           + lastMinute, null, Calls.DATE + " desc");
c.moveToFirst();

if (c.getCount() > 0) {
    int duration = Integer.parseInt(c.getString(c.getColumnIndex(Calls.DURATION)));
}

如果持续时间> 0,则呼叫被应答。

if duration is > 0 then then it call was answered.

显然有,你应该用它来确定CALL_STATE_IDLE被称为被打了一个电话后,其他标志。

Obviously there are other flags that you should use to determine that CALL_STATE_IDLE is called after a call was made.

希望有所帮助,并把你的corret方式为你正在做什么。

Hope that helps and put you in the corret way for what you are trying to do.

这篇关于我如何获得在android手机一呼出的状态呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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