gpt4 book ai didi

android - 如何在android中检索最近的通话列表和收藏夹列表?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:03:35 25 4
gpt4 key购买 nike

我需要通过点击相应的按钮来调用最近的通话列表和最喜欢的通话列表,并且需要我自己的列表布局中的数据。我是 android 的新手并且在这方面遇到了很多麻烦。任何人都可以帮助我..提前致谢..

最佳答案

一些额外的有用代码:

getFavoriteContacts:

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;
}

getRecentContacts:

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;
}

关于android - 如何在android中检索最近的通话列表和收藏夹列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7995183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com