Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中呼叫结束进程的操作事件_Android_Android Intent_Broadcastreceiver_Phone Call - Fatal编程技术网

android中呼叫结束进程的操作事件

android中呼叫结束进程的操作事件,android,android-intent,broadcastreceiver,phone-call,Android,Android Intent,Broadcastreceiver,Phone Call,我正在开发一个应用程序,我想在其中跟踪传出呼叫及其持续时间。例如,如果一个移动电话用户拨打我使用的电话。操作\u新建\u传出\u呼叫。*当他切断呼叫时,要执行什么操作?*我参考了所有教程,他们建议使用设备调用日志URI。但我想在broadcastreceiver中这样做。提前谢谢 public class MyCallReceiver extends BroadcastReceiver{ public void onReceive(Context context, Intent

我正在开发一个应用程序,我想在其中跟踪传出呼叫及其持续时间。例如,如果一个移动电话用户拨打我使用的电话。操作\u新建\u传出\u呼叫。*当他切断呼叫时,要执行什么操作?*我参考了所有教程,他们建议使用设备调用日志URI。但我想在broadcastreceiver中这样做。提前谢谢

  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);
试试这个:

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

请发布
adb logcat
输出,包括异常跟踪部分引起的。@18446744073709551615我可以在运行此应用程序时获得所拨打的号码。仍然没有异常。我要求像action Dialling(action\u NEW\u OUTGOING\u CALL)一样结束呼叫的任何其他活动…请发布
adb logcat
输出,包括异常跟踪的“由引起”部分。@18446744073709551615我可以在运行此应用程序时获得所拨打的号码。我仍然没有收到异常。我正在请求类似操作拨号(操作新呼叫和传出呼叫)的任何其他活动来结束呼叫。。。