首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android Content Providers(3)——Contacts Provider

2012-09-07 
Android Content Providers(三)——Contacts ProviderDisplays the Edit Contact screen in the contacts ap

Android Content Providers(三)——Contacts Provider


Displays the Edit Contact screen in the contacts application. The extras values you add to the intent are displayed. When the user clicksDone to save the edits, your activity returns to the foreground.


这里提供一种通过Intent来使用的方法,还有其他的使用方式,具体使用方式如下:

// Gets values from the UI

String name = mContactNameEditText.getText().toString();

String phone = mContactPhoneEditText.getText().toString();

String email = mContactEmailEditText.getText().toString();

String company = mCompanyName.getText().toString();

String jobtitle = mJobTitle.getText().toString();

// Creates a new intent for sending to the device's contacts application

Intent insertIntent =newIntent(ContactsContract.Intents.Insert.ACTION);

// Sets the MIME type to the one expected by the insertion activity

insertIntent.setType(ContactsContract.RawContacts.CONTENT_TYPE);

// Sets the new contact name

insertIntent.putExtra(ContactsContract.Intents.Insert.NAME, name);

// Sets the new company and job title

insertIntent.putExtra(ContactsContract.Intents.Insert.COMPANY, company);

insertIntent.putExtra(ContactsContract.Intents.Insert.JOB_TITLE, jobtitle); 


最后,在使用系统联系人的时候,需要加上两个权限:

<uses-permission android:name="android.permission.READ_CONTACTS">

<uses-permission android:name="android.permission.WRITE_CONTACTS">


详细文档可以参考:http://developer.android.com/guide/topics/providers/contacts-provider.html


关于这部分内容我还有些理解的不是很到位的地方,后续会继续学习,感兴趣的朋友可以一起研究。

欢迎关注我的新浪微博和我交流:@唐韧_Ryan


热点排行