当今,大部分的应用都涉及到要获取系统的内部资源,现教刚入门的android爱好者如何快速获取系统联系人的方法。
要获取系统联系人,我们就得用到ContentResolver(内容解析者),还有记得要加权限(READ_CONTACTS),否则就无法获取到系统联系人了。
第一步:获得解析者对象
ContentResolver resolver = getContentResolver();
第二步:通过解析者对象去查询系统联系人
Cursor c = resolver.query(Phones.CONTENT_URI, null, null, null, null);
第三步:实例化简单的游标适配器SimpleCursorAdapter,以便将系统联系人显示在listview上
String[] from=new String[]{Phones.NAME,Phones.NUMBER};
int[] to=new int[]{R.id.textView1,R.id.textView2};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.lus, c, from, to);
第四步:设置适配器
listview.set(adapter);
大功告成,这样就可以简单的实现快速获取系统联系人了。
本文出自 “一路向前” 博客,请务必保留此出处http://963916071.blog.51cto.com/8792403/1393112
教你如何快速获取系统联系人的方法,布布扣,bubuko.com
原文:http://963916071.blog.51cto.com/8792403/1393112