Android-往来:添加到联系人

//添加到联系人。使用事务
    public void testAddContact()  {
    
    	String name[]={"周杰伦","谢霆锋","言承旭","林俊杰","潘玮柏","明道"," 甄子丹"," 周渝民",
    			"罗志祥", "五月天","刘德华"," 麦浚龙"," 成龙"," 苏有朋"," 郭品超"," 阿杜"
    			,"郑嘉颖"," 吴尊"," 炎亚纶"," 王绍伟"," 唐禹哲"," 巫迪文"," 汪东城" };
    	for(String ss:name)
    	{
    		//首先插入空值,再得到rawContactsId 。用于以下插值   
            ContentValues values = new ContentValues ();   
            //insert a null value  
            Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI,values);   
            long rawContactsId = ContentUris.parseId(rawContactUri);   
          
            //往刚才的空记录中插入姓名   
            values.clear();   
            //A reference to the _ID that this data belongs to  
            values.put(StructuredName.RAW_CONTACT_ID,rawContactsId);   
            //"CONTENT_ITEM_TYPE" MIME type used when storing this in data table  
            values.put(Data.MIMETYPE,StructuredName.CONTENT_ITEM_TYPE);   
            //The name that should be used to display the contact.  
            values.put(StructuredName.DISPLAY_NAME,ss);   
            //insert the real values  
            getContentResolver().insert(Data.CONTENT_URI,values);   
            //插入电话   
            values.clear();   
            values.put(Phone.RAW_CONTACT_ID,rawContactsId);   
            //String "Data.MIMETYPE":The MIME type of the item represented by this row  
            //String "CONTENT_ITEM_TYPE": MIME type used when storing this in data table.  
            values.put(Data.MIMETYPE,Phone.CONTENT_ITEM_TYPE);   
            values.put(Phone.NUMBER,"1008611");   
            getContentResolver().insert(Data.CONTENT_URI,values);   
    	}
    	
    }

版权声明:本文博客原创文章。博客,未经同意,不得转载。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值