相同的MIME类型字符串在比较操作时不会返回true

时间:2013-07-13 17:21:15

标签: android android-contentprovider android-contacts

我似乎无法使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获得常量MIMETYPE而不是Data(似乎无法在那里找到常量。让我知道数据中是否有常量)它应该与我的查询中的MIMETYPE相同,但是也许他们实际上是不同的。除此之外,我不知道它为什么不起作用。

0 个答案:

没有答案