gpt4 book ai didi

android - 过滤带前缀号码的联系人

转载 作者:行者123 更新时间:2023-11-29 19:03:07 24 4
gpt4 key购买 nike

我有在 android 中加载所有联系电话的功能,现在我想过滤所有前缀为“0878”、“0877”、“0817”的联系电话,以便加载具有该前缀的联系电话,这里是我当前的代码:

private void loadContact(){
ContentResolver cr = applicationContext.getContentResolver();
String [] PROJECTION = ContactsQuery.PROJECTION;

Cursor cursor = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
PROJECTION,
null,
null,
null
);

while (cursor.moveToNext()) {
//String name = cursor.getString(ContactsQuery.DISPLAY_NAME);
String lookUpKey = cursor.getString(ContactsQuery.LOOKUP_KEY);
loadContactDetail(lookUpKey);
}
cursor.close();
}

private void loadContactDetail(String lookUpKey){
ContentResolver cr = applicationContext.getContentResolver();

String [] COLS = {ContactsContract.CommonDataKinds.Phone.NUMBER};

Cursor cursor = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, COLS,
ContactsContract.Data.LOOKUP_KEY + " = ?",
new String[]{lookUpKey},
null
);

while (cursor.moveToNext()) {
String phone = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
String formatted = Util.formatMSISDN(phone);
if(formatted != null)
contactsSet.add(formatted);
}
cursor.close();
}

最佳答案

试试这个。

    while (cursor.moveToNext()) {
String phone = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
String formatted = Util.formatMSISDN(phone);
if(formatted != null){
if(formatted.startsWith("0878") || formatted.startsWith("0877") || formatted.startsWith("0817"))
contactsSet.add(formatted);
}
}
cursor.close();

关于android - 过滤带前缀号码的联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48149751/

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