浅水咸鱼
2016-03-06 05:49android如何获取电话联系人列表,我这样写错在哪
8private ReadNameAndNum rnan;
private Thread t1 ;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
callView=View.inflate(this, R.layout.call, null);
callViewLayer=new LockUtil(this);
callViewLayer.setLockView(callView);
callViewLayer.lock();
callView.findViewById(R.id.callBack).setOnClickListener(this);
rnan=new ReadNameAndNum();
t1=new Thread(rnan);
t1.start();
}
class ReadNameAndNum implements Runnable{
ContentResolver cr= getContentResolver();
Cursor c=cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
@Override
public void run() {
System.out.println(">>>>>RUN");
while (c.moveToNext()) {
int nameFieldColumnIndex= c.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String contact=c.getString(nameFieldColumnIndex);
int numberFieldColumnIndex=c.getColumnIndex(PhoneLookup.NUMBER);
String number=c.getString(numberFieldColumnIndex);
System.out.println(">>>>>"+contact+">>>>"+number);
}
c.close();
}}
```报错日志
20:35.177: I/System.out(19335): >>>>>onStart
03-06 13:20:35.177: I/System.out(19335): >>>>>onResume
03-06 13:20:37.027: I/System.out(19335): >>>>CallClick
03-06 13:20:57.297: W/ServiceManager(19335): Permission failure: android.p ermission.READ_CONTACTS from uid=10104 pid=19335
03-06 13:20:57.297: E/CheckPermission(19335): Permission Denial: can't read contacts pid=19335, uid=10104
03-06 13:20:57.307: I/System.out(19335): >>>>>CAllonStart
03-06 13:20:57.307: I/System.out(19335): >>>>>CAllonResume
03-06 13:20:57.317: I/System.out(19335): >>>>>RUN
03-06 13:20:57.317: W/dalvikvm(19335): threadid=16: thread exiting with uncaught exception (group=0x41697898)
03-06 13:20:57.327: E/AndroidRuntime(19335): FATAL EXCEPTION: Thread-1466
03-06 13:20:57.327: E/AndroidRuntime(19335): java.lang.NullPointerException
03-06 13:20:57.327: E/AndroidRuntime(19335): at com.example.deng_00_lock.AtyCall$ReadNameAndNum.run(AtyCall.java:42)
03-06 13:20:57.327: E/AndroidRuntime(19335): at java.lang.Thread.run(Thread.java:841)
03-06 13:20:57.397: I/Choreographer(19335): Skipped 1207 frames! The application may be doing too much work on its main thread.
读取权限我也加了,但仍不成功,这里我开了一个线程
- 点赞
- 回答
- 收藏
- 复制链接分享
7条回答
为你推荐
- android如何获取电话联系人列表,我这样写错在哪
- android
- 7个回答
- Android如何获取listview里面的选取的数据
- android
- list
- 9个回答