gpt4 book ai didi

android - android中调用结束过程的 Action 事件

转载 作者:行者123 更新时间:2023-11-30 03:16:04 25 4
gpt4 key购买 nike

我正在开发一个应用程序,我想在其中跟踪拨出电话及其持续时间。例如,如果手机用户调用电话,我使用了 Intent.ACTION_NEW_OUTGOING_CALL。*当他挂断电话时,要实现什么操作?*我引用了所有教程,他们建议使用设备调用日志 URI。但我想在广播接收器中执行此操作。提前致谢。

  public class MyCallReceiver extends BroadcastReceiver{
public void onReceive(Context context, Intent intent) {

if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {

String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

}

}
}

最佳答案

试试这个:

Boolean wasnumberdialed=false;
Boolean callpicked=false;

//if dialed below is called
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
wasnumberdialed=true;
}

//if the call is received by the recipient then this is executed and its an
//outgoing call,(wasnumberdialed is set to true only for outgoing calls) we
//need to ignore incoming calls. If wedont check this an incoming call
//would also execute this.
if (intent.getAction().equals(Intent.CALL_STATE_OFFHOOK && wasnumberdialed)) {
//start your timer to count the time of call
//long start_time = System.currentTimeMillis();
callpicked=true;
}

//after the call is disconnected and was received which is an outgoing call below is
//executed
if (intent.getAction().equals(Intent.EXTRA_STATE_IDLE && callpicked)) {
//end your timer here
//long end_time = System.currentTimeMillis();
}

Log.v("myapp","Total call time is "+TimeUnit.MILLISECONDS.toMinutes(end_time-start_time)+" mins);

关于android - android中调用结束过程的 Action 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20117056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com