This article summarizes a section of Android to get the call time program code, the need for friends to refer to.
We know that the phone length of the Android system should be callog, so it is advisable to check contactprovider, or Telephonyprovider
Service Test
Can start when the call starts service record current time A, then stopself (); In addition, start the service again at the end of the call, get the current time B again, and compare time a with B.
String time = long.tostring (when the comparison is processed)
and then call
Copy Code code as follows:
Toast.maketext (this, time, Toast.length_short). Show ();
Make it appear, then stopself ();
Get the length of contact call time Java code
Copy Code code as follows:
Cursor Cursor = Getcontentresolver (). Query (Calls.content_uri,
New string[] {calls.duration, Calls.type, calls.date},
Null
Null
Calls.default_sort_order);
MainActivity.this.startManagingCursor (cursor);
Boolean Hasrecord = Cursor.movetofirst ();
Long incoming = 0L;
Long outgoing = 0L;
int count = 0;
while (Hasrecord) {
int type = Cursor.getint (Cursor.getcolumnindex (Calls.type));
Long Duration = Cursor.getlong (Cursor.getcolumnindex (calls.duration));
Switch (type) {
Case Calls.incoming_type:
Incoming + = duration;
Break
Case Calls.outgoing_type:
Outgoing + = Duration;
Default
Break
}
count++;
Hasrecord = Cursor.movetonext ();
}
Toast.maketext (Mainactivity.this,
"Total" + Count + "second call." Total call Length "+ (incoming + outgoing) +" seconds. Where to listen "+ Incoming +" seconds, pull hit "
+ Outgoing + "seconds.",
Toast.length_long). Show ();