这是我获取持续时间通话时间的代码:
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();
}
但是这个函数无法获取最后一次调用的数据。如果我拨2个电话,第一个电话是5秒,第二个电话是10秒,Toast只显示“5s”,应该是“15s”。有谁让我知道我错了什么?谢谢!