根據RawContactID判斷聯繫人來自手機還是SIM卡

private List<TxrjAccount> accounts = new ArrayList<TxrjAccount>(); 
private HashMap<Integer, TxrjAccount> accountMap = new HashMap<Integer, TxrjAccount>();

public AsyncQueryContacts(ContentResolver cr) { 
    super(cr); 
    initAccounts(); 
}

private void initAccounts() { 
    Cursor cursor = mContext.getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, 
            new String[] {RawContacts._ID, RawContacts.ACCOUNT_NAME, RawContacts.ACCOUNT_TYPE }, 
            null, null, null); 
    if (cursor != null) { 
        TxrjAccount account = null; 
        while (cursor.moveToNext()) { 
            int id = cursor.getInt(cursor.getColumnIndex(RawContacts._ID)); 
            String name = cursor.getString(cursor.getColumnIndex(RawContacts.ACCOUNT_NAME)); 
            String type = cursor.getString(cursor.getColumnIndex(RawContacts.ACCOUNT_TYPE)); 
            account = new TxrjAccount(id, name, type); 
            accounts.add(account); 
            accountMap.put(id, account); 
        } 
        cursor.close(); 
    } 
}

//在AsyncQueryContacts.onQueryComplete()方法中。

if(contact.getPhoneList().size() == 1){ 
    contact.setbSim(accountMap.get(phone.getRawContactId()).isSimAccount()); 
} 

//在TxrjAccount類中。

public static final String PHONE_ACCOUNT_NAME = "vnd.sec.contact.phone"; 
public static final String PHONE_ACCOUNT_TYPE = "vnd.sec.contact.phone"; 
public static final String SIM2_ACCOUNT_NAME = "primary.sim2.account_name"; 
public static final String SIM2_ACCOUNT_TYPE = "vnd.sec.contact.sim2"; 
public static final String SIM_ACCOUNT_NAME = "primary.sim.account_name"; 
public static final String SIM_ACCOUNT_TYPE = "vnd.sec.contact.sim"; 

public boolean isSimAccount() { 
    if(type.equals(SIM_ACCOUNT_TYPE) || type.equals(SIM2_ACCOUNT_TYPE)) { 
        return true; 
    } else { 
        return false; 
    } 
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章