android 4.0 读取联系人的问题
这是java代码:public class ReadContactActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button queBtn = (Button)findViewById(R.id.query);
queBtn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
readContact();
}
}
);
}
public void readContact()
{
Cursor cursor = this.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while(cursor.moveToFirst())
{
int index = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String name = cursor.getString(index);
Toast.makeText(this, name, Toast.LENGTH_SHORT).show();
}
}
}
这是描述文件:
请高手看看是哪里不对?运行的时候出现出错! --------------------编程问答-------------------- 看看logcat有啥异常信息 --------------------编程问答-------------------- cursor.moveToNext() --------------------编程问答-------------------- 你的目的就是要读出联系人一些信息吧。 有名字电话什么的。但是你用uri不对
public void readContact()
{
Cursor cursor = this.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if(cursor!=null){
while(cursor.moveToFirst())
{
for(;!cursor.isAfterLast();cursor.moveToNext()){
int index = cursor.getColumnIndex(Contacts.DISPLAY_NAME);
String name = cursor.getString(index);
Toast.makeText(this, name, Toast.LENGTH_SHORT).show();
}
}
}
}
试试这个吧。 --------------------编程问答-------------------- 擦,上面打字打错了 。。uri没有问题。
如果是要查找一次查找全部信息 上面的uri就不行了
要用到 PhoneLookup.content_filter_uri --------------------编程问答-------------------- 4.0好像读联系人有问题,你试试用2.1--2.3版本读试试,要是没问题说明是版本的问题了,而不是你代码的问题。
补充:移动开发 , Android