Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.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
无法获取上次持续通话时间(Java/Android)_Java_Android - Fatal编程技术网

无法获取上次持续通话时间(Java/Android)

无法获取上次持续通话时间(Java/Android),java,android,Java,Android,这是我获取通话持续时间的代码: public void getCallDuration() { managedCursor = this.getContentResolver().query( CallLog.Calls.CONTENT_URI, null, null, null, null); int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION); Call_

这是我获取通话持续时间的代码:

public void getCallDuration() {

    managedCursor = this.getContentResolver().query(
            CallLog.Calls.CONTENT_URI, null, null, null, null);

    int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);

    Call_Duration = 0;
     while (managedCursor.moveToNext()){

        String callDuration = managedCursor.getString(duration);
        Call_Duration = Call_Duration + Integer.parseInt(callDuration);

     }

    SharedPreferences settings = this.getApplicationContext()
            .getSharedPreferences("OWS", 0);
    SharedPreferences.Editor editor = settings.edit();
    editor.putInt("Time_Passed", Call_Duration);
    editor.commit();

     Toast.makeText(this, ""+Call_Duration, Toast.LENGTH_LONG).show();

}

但此函数无法获取上次调用的数据。如果我打两次电话,第一次是5秒,第二次是10秒,吐司只显示“5秒”,应该是“15秒”。有人告诉我我做错了什么吗?谢谢

不要解析为一个
整数
,也不要使用
字符串
记住那些是毫秒请参阅