Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-检查联系人是否只有公司名称_Android - Fatal编程技术网

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

Android-检查联系人是否只有公司名称,android,Android,我想检查我名单上的联系人是否只有姓名和公司名称,而没有其他信息 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

我想检查我名单上的联系人是否只有姓名和公司名称,而没有其他信息

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
   }
 }
有关详细说明,请浏览链接