在contacts中添加自定义mime type

public void saveFormality() { 
        try { 
            ContentValues values = new ContentValues(); 
            values.put(Data.DATA1, this.getFormality() ? "1" : "0"); 
            int mod = ctx.getContentResolver().update( 
                    Data.CONTENT_URI, 
                    values, 
                    Data.CONTACT_ID + "=" + this.getId() + " AND " 
                            + Data.MIMETYPE + "= '" 
                            + clsContacts.FORMALITY_MIMETYPE + "'", null); 
 
            if (mod == 0) { 
                values.put(Data.CONTACT_ID, this.getId()); 
                values.put(Data.MIMETYPE, clsContacts.FORMALITY_MIMETYPE); 
                ctx.getContentResolver().insert(Data.CONTENT_URI, values); 
            } 
        } catch (Exception e) { 
            Log.v(TAG(), "saveFormality failed"); 
        } 
    } 
 
public boolean getFormality() { 
     if (data.containsKey(FORMALITY)) { 
        return data.getAsBoolean(FORMALITY); 
    } else { 
        // read formality 
        Cursor c = readDataWithMimeType(clsContacts.MIMETYPE_FORMALITY, this.getId()); 
        if (c != null) { 
            try { 
                if (c.moveToFirst()) { 
                    this.setFormality(c.getInt(0) == 1); 
                    return (c.getInt(0) == 1); 
                } 
            } finally { 
                c.close(); 
            } 
        } 
        return false; 
    } 
 
} 

 上面的是添加了一个boolean在联系人中,2.1以上适用

你可能感兴趣的:(C++,c,C#)