Access the calllog of the Android platform

Source: Internet
Author: User

The Android platform is indeed very open. You can call almost any underlying interface, or even intercept text messages or incoming calls. These are incomparable to the j2s platform. This topic describes how to access the call history of Android.

The call records on the Android platform are stored on the mobile phone in the form of content provider. Therefore, you need to use contentresolver to query the call records and return the cursor interface. As follows:

Package com. Me;

Import Android. App. listactivity;
Import Android. database. cursor;
Import Android. OS. Bundle;
Import Android. provider. calllog;
Import Android. widget. simpleadapter;
Import Android. widget. simplecursoradapter;

Public class calllogactivity extends listactivity {

@ Override
Protected void oncreate (bundle arg0 ){
Super. oncreate (arg0 );
Setcontentview (R. layout. Main );
Cursor cursor = getcontentresolver (). Query (calllog. CILS. content_uri,
Null, null, null, calllog. CILS. default_sort_order );
Startmanagingcursor (cursor );
Simplecursoradapter adapter = new simplecursoradapter (this,
Android. R. layout. simple_list_item_1, cursor,
New String [] {calllog. CILS. Number },
New int [] {Android. R. Id. text1 });

Setlistadapter (adapter );
}

}

After obtaining the cursor, You can construct an adapter and call setlistadapter () to display the call record on the screen. The calllog class defines the CILS class, and a large number of internal classes can be seen in Android. CILS defines many constants for you to access call records, including two Uris and multiple field definitions, such as the number we use here. For more information, see andorid Doc.

Below is/RES/layout/Main. xml

<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">

<Listview Android: Id = "@ + ID/Android: List"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"/>
<Textview Android: Id = "@ + ID/Android: empty"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: text = "no notes! "/>
</Linearlayout>

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.