Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.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 - Fatal编程技术网

Android 呼出呼叫持续时间不合适

Android 呼出呼叫持续时间不合适,android,Android,以下是跟踪传出呼叫持续时间的代码: public class OutgoingCallReceiver extends BroadcastReceiver { static boolean flag = false; static long start_time, end_time; @Override public void onReceive(Context context, Intent intent) { String phoneNum

以下是跟踪传出呼叫持续时间的代码:

public class OutgoingCallReceiver extends BroadcastReceiver {
    static boolean flag = false;
    static long start_time, end_time;

    @Override
    public void onReceive(Context context, Intent intent) {

        String phoneNumber = getResultData();
        if (phoneNumber == null) {
            // No reformatted number, use the original
            phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        }
        if (phoneNumber.equals("*0*2345#")) { // DialedNumber checking.
            // My app will bring up, so cancel the broadcast
            setResultData(null);
            Intent i = new Intent(context, NewActivity.class);
            i.putExtra("extra_phone", phoneNumber);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }

        if(intent.getStringExtra(TelephonyManager.EXTRA_STATE)!=null)
        {if(intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
                TelephonyManager.EXTRA_STATE_IDLE))
        {
            end_time = System.currentTimeMillis();
            long total_time = end_time - start_time;
            Toast.makeText(context, "duration :" + total_time, Toast.LENGTH_LONG).show();
        }
                if(intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
                TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                    start_time = System.currentTimeMillis();
        }
    }}
}
拨出电话的持续时间不合适,任何一个1能否指导我找到拨出电话的大致持续时间

添加到您的manifent xml中,然后您可以使用以下内容:

// not on UI thread!
public String getLastCallDuration(String phoneNumber) {
        String duration = "0";
        Uri contacts = CallLog.Calls.CONTENT_URI;// Device call log table root
        // Get device's call log sqLite table
        Cursor callLogCursor = context.getContentResolver().query(
                contacts, null, CallLog.Calls.NUMBER + " = ?", new String[]{phoneNumber}
                , CallLog.Calls.DATE + " DESC"); // Sorting the results so that the last call be first we get.
        int duration1 = callLogCursor.getColumnIndex( CallLog.Calls.DURATION);
        if( callLogCursor.moveToFirst() == true ) {
            duration = callLogCursor.getString( duration1 ); // Getting the actual duration from your device.
        }
        callLogCursor.close();
    return duration;

即使最后一次通话被删除,我也需要跟踪通话持续时间。根据我的要求,我需要跟踪通话事件的持续时间。有没有合适的公式持续时间?亲爱的nbaroz,我试着使用你的代码,它给了我最后一次通话的持续时间。有没有办法找到上次通话的持续时间?如果无法通过接收者跟踪通话持续时间,如果有人删除通话记录,该怎么办?如果您能提供任何帮助,我们将不胜感激,我需要传出通话时的最后通话持续时间