【问题标题】:Action event for call ending process in androidandroid中呼叫结束过程的动作事件
【发布时间】:2013-11-21 09:30:31
【问题描述】:

我正在开发一个应用程序,我想在其中跟踪拨出电话及其持续时间。例如,如果手机用户拨打电话,我使用 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);

       }    

    }
  }

【问题讨论】:

  • 请发布adb logcat 输出,包括异常跟踪的引起部分。
  • @18446744073709551615 当我运行这个应用程序时,我可以得到拨打的号码。我仍然没有例外。我要求像操作拨号(ACTION_NEW_OUTGOING_CALL)一样结束通话的任何其他活动......跨度>

标签: android android-intent broadcastreceiver phone-call


【解决方案1】:

试试这个:

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多