Android 获取Sim卡联系人

package com.dascom.ssmn.util;

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.Photo;

public class SimUtil {

	
    private static final String[] PHONES_PROJECTION = new String[] {Phone.DISPLAY_NAME, Phone.NUMBER, Photo.PHOTO_ID,Phone.CONTACT_ID };  
	
    /**联系人显示名称**/  
    private static final int PHONES_DISPLAY_NAME_INDEX = 0;  
      
    /**电话号码**/  
    private static final int PHONES_NUMBER_INDEX = 1;  
      
    /**头像ID**/  
    private static final int PHONES_PHOTO_ID_INDEX = 2;  
     
    /**联系人的ID**/  
    private static final int PHONES_CONTACT_ID_INDEX = 3;   
	
    public static String getCalllogPhoneName(Activity activity, String phoneNum) {
		
	String contactName = phoneNum;
	//获取sim卡联系人  
        Uri uri = Uri.parse("content://icc/adn");  
        
        Cursor phoneCursor = activity.getContentResolver().query(uri, PHONES_PROJECTION, null, null, null);
		if (phoneCursor != null) {
			while (phoneCursor.moveToNext()) {
				// 得到手机号码  
		        String phoneNumber = phoneCursor.getString(PHONES_NUMBER_INDEX);  
		        // 当手机号码为空的或者为空字段 跳过当前循环  
		        if (phoneNumber == null || "".equals(phoneNumber)) {
		        	continue; 
		        } else if (phoneNumber.equals(phoneNum)) {
		        	// 得到联系人名称  
		        	contactName = phoneCursor.getString(PHONES_DISPLAY_NAME_INDEX);  
		        	break;
		        }
		        
			}
		}
		phoneCursor.close();
		return contactName;
	}
}

你可能感兴趣的:(Android 获取Sim卡联系人)