English 中文(简体)
• 如何检索最新呼吁清单和在甲体内的偏爱物清单?
原标题:how to retrieve recent call list and favourites list in android?
  • 时间:2011-11-03 12:52:37
  •  标签:
  • android

我需要在各县的点击点上打上最近的电话名单和偏袒的电话名单,并且需要我自己的名单上的数据。 我是新鲜的,对此有很多麻烦。 任何人都可以事先帮助我。

最佳回答

For getting recent calls list,you can use CallLog in android. Here is a good tutorial.This is also helpful.

你们可以把它用于所有即将发出的呼吁:

Cursor cursor = getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI,null, android.provider.CallLog.Calls.TYPE+"="+android.provider.CallLog.Calls.OUTGOING_TYPE, null,null);

各类电话:

Cursor cursor = getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI,null, null, null,null);
问题回答

具有一些额外的有用守则:

获得FavoriteContacts:

Map getFavoriteContacts(){
Map contactMap = new HashMap();

Uri queryUri = ContactsContract.Contacts.CONTENT_URI;

String[] projection = new String[] {
        ContactsContract.Contacts._ID,
        ContactsContract.Contacts.DISPLAY_NAME,
        ContactsContract.Contacts.STARRED};

String selection =ContactsContract.Contacts.STARRED + "= 1 ";

Cursor cursor = getContentResolver().query(queryUri, projection, selection,null,null);


while (cursor.moveToNext()) {
    String contactID = cursor.getString(cursor
            .getColumnIndex(ContactsContract.Contacts._ID));

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID));
    intent.setData(uri);
    String intentUriString = intent.toUri(0);

    String title = (cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));

    contactMap.put(title,intentUriString);

}
cursor.close();
return contactMap;
}

加入:

Map getRecentContacts(){
Map contactMap = new HashMap();

Uri queryUri = android.provider.CallLog.Calls.CONTENT_URI;

String[] projection = new String[] {
        ContactsContract.Contacts._ID,
        CallLog.Calls._ID,
        CallLog.Calls.NUMBER,
        CallLog.Calls.CACHED_NAME,
        CallLog.Calls.DATE};

String sortOrder = String.format("%s limit 500 ", CallLog.Calls.DATE + " DESC");


Cursor cursor = getContentResolver().query(queryUri, projection, null,null,sortOrder);


while (cursor.moveToNext()) {
    String phoneNumber = cursor.getString(cursor
            .getColumnIndex(CallLog.Calls.NUMBER));

    String title = (cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME)));

    if(phoneNumber==null||title==null)continue;

    String uri = "tel:" + phoneNumber ;
    Intent intent = new Intent(Intent.ACTION_CALL);
    intent.setData(Uri.parse(uri));
    String intentUriString = intent.toUri(0);

    contactMap.put(title,intentUriString);

}
cursor.close();
return contactMap;
}

你们可以使用以下《 Java法》来获得最近的呼吁清单:

Cursor phones = getActivity().getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null,null);

while (phones.moveToNext()) {
    String phoneNumber = phones.getString(phones.getColumnIndex(CallLog.Calls.NUMBER));

    if (phoneNumber.length() > 6) {
        String name = phones.getString(phones.getColumnIndex(CallLog.Calls.CACHED_NAME));

        numbers.add(phoneNumber);

    }
} 




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签