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>