This is my code for get amount of duration call time :
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();
}
But this function can not get data of last call. If I make 2 call, first call is 5s and second call is 10s, Toast only show "5s", it should be "15s". Anybody let me know what I wrong ? Thanks !