将电话簿获取到应用程序
我编写了以下代码来获取联系方式。问题是我收到的电话号码显示为空。你能帮助我吗?
private void displayRecords() {
// An array specifying which columns to return.
String columns[] = new String[] { People.NAME, People.NUMBER_KEY};
Uri mContacts = People.CONTENT_URI;
Cursor cur = managedQuery(mContacts, columns, // Which columns to return
null, // WHERE clause; which rows to return(all rows)
null, // WHERE clause selection arguments (none)
null // Order-by clause (ascending by name)
);
if (cur.moveToFirst()) {
String name = null;
String phoneNo = null ;
do {
// Get the field values
name = cur.getString(cur.getColumnIndex(People.NAME));
phoneNo =cur.getString(cur.getColumnIndex(People.NUMBER_KEY));
Toast.makeText(this, name + " " + phoneNo, Toast.LENGTH_LONG).show();
} while (cur.moveToNext());
}
}
I wrote the following code to get the contact details. The problem is the phone number I am getting is showing null. Can You help me?
private void displayRecords() {
// An array specifying which columns to return.
String columns[] = new String[] { People.NAME, People.NUMBER_KEY};
Uri mContacts = People.CONTENT_URI;
Cursor cur = managedQuery(mContacts, columns, // Which columns to return
null, // WHERE clause; which rows to return(all rows)
null, // WHERE clause selection arguments (none)
null // Order-by clause (ascending by name)
);
if (cur.moveToFirst()) {
String name = null;
String phoneNo = null ;
do {
// Get the field values
name = cur.getString(cur.getColumnIndex(People.NAME));
phoneNo =cur.getString(cur.getColumnIndex(People.NUMBER_KEY));
Toast.makeText(this, name + " " + phoneNo, Toast.LENGTH_LONG).show();
} while (cur.moveToNext());
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个代码,它会对你有帮助
try this code it will helpful for u