簡體   English   中英

Android:在收藏夾聯系人中獲取電話號碼

[英]Android: Get Phone Numbers in Favorites Contacts

我想在聯系人的“收藏夾”菜單中獲取所有電話號碼,這是我的代碼的一部分

此代碼獲取我所有的聯系人姓名和ID

ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
if (cur.getCount() > 0) {
    while (cur.moveToNext()) {
        String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
        String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
    }
}

這是我得到我的號碼的地方

phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +"="+ CheckedArray.get(i), null, null); 
phones.moveToNext();
phoneNumber = phones.getString(phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER));
String Message = DbManager.getInstance().userName+" wants to share his OneLinx profile with you";
try {
    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, Message, null, null);    
} catch (Exception e) {
    Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
    e.printStackTrace();
}       
phones.close();

但是在我的應用程序的另一部分中,我只想獲取收藏夾中的聯系人,所以有辦法嗎? 我可以在此處更改某些內容以僅獲取收藏夾而不是所有聯系人嗎?

我建議您使用ContentProvider.query方法的參數selection和selectionArgs。 因此,您可以過濾“已加星標”(或收藏夾)的那些聯系電話。

在選擇參數中,只需添加包含Phone.STARRED +“ = 1”的字符串,以便提供商將為您提供加星標的聯系人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM