Android Acquisition Call time instance Analysis _android

Source: Internet
Author: User
Tags current time
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 ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.