根据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; 
    } 
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值