简体   繁体   English

Android:连接时电话呼叫检测?

[英]Android : Phone call detect when connected?

I can use this code to make outgoing call: 我可以使用此代码拨打电话:

Intent dial = new Intent(Intent.ACTION_CALL); 
dial.setData(Uri.parse("tel:5556") ); 
context.startActivity(dial);

But how to detect whether the call is picked up or the call is refused? 但是如何检测是否接听电话或拒绝接听电话? I tried PhoneStateListener, but it is not working. 我尝试过PhoneStateListener,但它无法正常工作。

Unfortunately, Android gives no mean to know when an outgoing call has been answered. 不幸的是,Android没有理由知道何时接听了拨出电话。

PhoneStateListener works fine but the 3 states notified by onCallStateChanged are not enough. PhoneStateListener工作正常,但onCallStateChanged通知的3个状态是不够的。 An additional state like CALL_STATE_CONNECTED would be welcome. 欢迎使用像CALL_STATE_CONNECTED这样的附加状态。

There is an open issue requesting this feature but it didn't get much attention so far: https://code.google.com/p/android/issues/detail?id=14266 有一个未解决的问题要求此功能,但到目前为止它没有受到太多关注: https//code.google.com/p/android/issues/detail?id = 14266

Some people (like me) falls back using logcat and tries to infer if an outgoing call has been answered but this is far from an ideal solution. 有些人(像我一样)使用logcat回退并尝试推断是否已经回答了拨出电话,但这远非理想的解决方案。

I am also searching for an answer to the same problem, apparently no straight forward method is present to do this. 我也在寻找同样问题的答案,显然没有直接的方法来做到这一点。 But, I think we can combine a Call Log content observer with PhoneStateListener to get the call duration. 但是,我认为我们可以将Call Log内容观察者与PhoneStateListener结合起来以获得呼叫持续时间。 We could set a flag in the shared prefs when an outgoing call is started, if anything changes in call log and our shared prefs flag is true we could get the call duration from the call log to see if the call was ever connected :) 我们可以在启动传出呼叫时在共享首选项中设置一个标志,如果调用日志中有任何更改并且我们的共享首选标志为真,我们可以从呼叫日志中获取呼叫持续时间,以查看呼叫是否曾连接过:)

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

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