Android获取Contact Number的例子(2.0系统以前的获取方式)
16lz
2021-01-25
Android获取Contact Number的例子(2.0系统以前的获取方式)
- String[]projection=newString[]{
- People._ID,
- People.NAME,
- People.NUMBER,
- };
- //GetthebaseURIforPeopletableinContactscontentprovider.
- //whichis:content://contacts/people/
- UricontactUri=People.CONTENT_URI;
- //Bestwaytoretrieveaquery;returnsamanagedquery.
- CursorpeopleCursor=managedQuery(contactUri,
- projection,//Whichcolumnstoreturn.
- null,//WHEREclause--wewon'tspecify.
- null,//SelectionArgs??
- People.DEFAULT_SORT_ORDER);//Order-byname
- //gotothebeginningofthelist
- peopleCursor.moveToFirst();
- //So,herewehaveacontact.WeneedtogetthecontactID(_id)then
- //buildtheUritogetthephonessectionofthatuser'srecord
- //whichisasubdirectoryofacontactrecord
- longpersonId=peopleCursor.getLong(peopleCursor.getColumnIndex("_id"));
- UripersonUri=ContentUris.withAppendedId(contactUri,personId);
- //SonowtheURLlookslike:content://contacts/people/_id(wheretheactualidoftherecordishere)
- UriphoneUri=
- Uri.withAppendedPath(personUri,Contacts.People.Phones.CONTENT_DIRECTORY);
- //NowtheURLlookslike:content://contacts/people/_id/phones(wherephonesisliterally"phones")
- //Nowgetallthephonenumbersforthiscontact
- CursorphonesCursor=managedQuery(phoneUri,
- null,
- null,
- null,
- Phones.DEFAULT_SORT_ORDER);
- //WenowhaveacursorforallthephonenumbersforthatUserID
- //gotothebeginningofthephonelist.
- phonesCursor.moveToFirst();
更多相关文章
- GitHub 标星 2.5K+!教你通过玩游戏的方式学习 VIM!
- Nginx系列教程(六)| 手把手教你搭建 LNMP 架构并部署天空网络电影
- 基于Android的WebService开发例子
- MTK Android(安卓)平台开发之旅
- android 输入法框架简介
- Learning Android(安卓)Studio to build a app from scratch
- Android(安卓)Framework 分析
- Android(安卓)按钮响应点击事件的三种实现方式
- Linux 内核启动挂载android根文件系统过程分析