0

我似乎无法使 ContactsContract.CommonDataKinds MIMETYPE 常量与我在游标中查询的那个相匹配。我已经测试了这两个字符串,它们看起来相同,但是当我在某个条件下比较它们时,它们不会返回“true”。

这是发生此问题的方法的代码片段:

    //gets all the information from the cursor and puts into its respective ArrayList
    for(int i=0; i<C.getCount(); i++){
        HashMap<String, String> info = new HashMap<String,String>();
        info.put(C.getString(3),C.getString(4));
        Log.d(TAG, "Itertation: "+i);
        Log.d(TAG, "Row Data MIMETYPE: "+C.getString(2));
        Log.d(TAG, "Phone MIMETYPE constant: "+ ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE); //this line and the above line return the exact same string when the data types match
        if(C.getString(2) == ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE){
            Log.d(TAG, "I have entered the phone condition");//does not enter even if they are identical
            phoneNum.add(info);
        }else if(C.getString(2) == ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE){
            Log.d(TAG, "I have entered the Email condition");//does not enter
            emailAddress.add(info);
        }else if(C.getString(2) == ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE){
            Log.d(TAG, "I have entered the Address condition");//does not enter
            postalAddress.add(info);
        }
        C.moveToNext();
    }

C.getString(2) 是该行的 MIMETYPe。这是查询及其参数的片段

//query properties
private Uri mUri = ContactsContract.Data.CONTENT_URI;
private String[] mProjections = {ContactsContract.Data.CONTACT_ID, ContactsContract.Data._ID, ContactsContract.Data.MIMETYPE, 
        ContactsContract.Data.DATA1, ContactsContract.Data.DATA2};
private String mSelection = ContactsContract.Data.CONTACT_ID+ "='"; //the ending of this gets added in the code
private String[] mArgs = null;
private String mSortOrder = null;

C = getContentResolver().query(mUri, mProjections, mSelection , mArgs, mSortOrder);

我不知道比较不会返回true。当我检查 LogChat 是否应该匹配的迭代时,我得到了这个:

07-13 17:11:48.764: D/ContactDetail(2904): Itertation: 0
07-13 17:11:48.764: D/ContactDetail(2904): Row Data MIMETYPE: vnd.android.cursor.item/phone_v2
07-13 17:11:48.764: D/ContactDetail(2904): Phone MIMETYPE constant: vnd.android.cursor.item/phone_v2

有谁知道为什么这不起作用?根据我的理解,即使我从 CommonDataKinds 而不是 Data 获得常量 MIMETYPE(似乎无法在那里找到常量。让我知道 Data 中是否有常量)它应该与我的查询中的 MIMETYPE 相同,但是也许他们实际上是不同的。除此之外,我不知道为什么它不起作用。

4

0 回答 0