gpt4 book ai didi

Android - 检查联系人是否只有公司名称

转载 作者:行者123 更新时间:2023-11-30 00:27:52 24 4
gpt4 key购买 nike

我想检查列表中的联系人是否只有姓名和公司名称,没有其他信息。

Cursor cursor = null;
if (Verify.notNull(email)) {
final Uri URI = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, Uri.encode(email));
final String[] PROJECTION = new String[]{Contacts.CONTACT_ID};
try {
cursor = cr.query(URI,
PROJECTION,
null,
null,
null);

if (cursor != null && cursor.moveToFirst() && !cursor.isNull(0)) {
return cursor.getInt(0);
}

但我不知道如何获取公司名称,然后检查联系人结构中是否只存在姓名和公司名称。

最佳答案

找到解决方案

if(dataCursor.moveToFirst()){
String companyName = "";
String displayName = "";
// Getting Display Name

displayName = dataCursor.getString(dataCursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME ));

//Getting Organization details

if(dataCursor.getString(dataCursor.getColumnIndex("mimetype")).equals(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)){
companyName = dataCursor.getString(dataCursor.getColumnIndex("data1"));
}
if(companyName!=null && !companyName.isEmpty() && displayName!=null && !displayName .isEmpty()){

// Here company name and name exists write your logic
}
}

详细解释请点击链接

http://wptrafficanalyzer.in/blog/android-contacts-content-provider-retrieving-and-listing-contacts-in-listview-example/

关于Android - 检查联系人是否只有公司名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45034282/

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