本文介绍了进不去的Android 2.3.3电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个简单的应用程序取得联系的电话号码。然而,在电话号码返回空。
下面是我的code:
私人无效queryContactPhoneNumber(){
// TODO自动生成方法存根
的String [] COLS =新的String [] {People.NAME,People.NUMBER};
乌里myContacts = People.CONTENT_URI;
光标mqCur = managedQuery(myContacts,COLS,NULL,NULL,NULL);
如果(mqCur.moveToFirst())
{
字符串MYNAME = NULL;
字符串为mynumber = NULL;
做
{
MYNAME = mqCur.getString(mqCur.getColumnIndex(People.NAME));
为mynumber = mqCur.getString(mqCur.getColumnIndex(People.NUMBER));
Toast.makeText(这一点,MYNAME ++为mynumber,Toast.LENGTH_SHORT).show();
}
而(mqCur.moveToNext());
}
}
解决方案
试试这个,
乌里myContacts = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; // People.CONTENT_URI;
光标mqCur = managedQuery(myContacts,NULL,NULL,NULL,NULL);
如果(mqCur.moveToFirst())
{
字符串MYNAME = NULL;
字符串为mynumber = NULL;
做
{
MYNAME = mqCur.getString(mqCur.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
为mynumber = mqCur.getString(mqCur
.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
Toast.makeText(这一点,MYNAME ++为mynumber,Toast.LENGTH_SHORT).show();
}
而(mqCur.moveToNext());
}
我想这会帮助你。
I write a simple application to get phone number in Contacts. However, the phone number return "null".
Here is my code:
private void queryContactPhoneNumber() {
// TODO Auto-generated method stub
String[] cols = new String[] {People.NAME, People.NUMBER};
Uri myContacts = People.CONTENT_URI;
Cursor mqCur = managedQuery(myContacts, cols, null, null, null);
if(mqCur.moveToFirst())
{
String myname = null;
String mynumber = null;
do
{
myname = mqCur.getString(mqCur.getColumnIndex(People.NAME));
mynumber = mqCur.getString(mqCur.getColumnIndex(People.NUMBER));
Toast.makeText(this, myname + " " + mynumber, Toast.LENGTH_SHORT).show();
}
while(mqCur.moveToNext());
}
}
解决方案
Try this,
Uri myContacts = ContactsContract.CommonDataKinds.Phone.CONTENT_URI ;//People.CONTENT_URI;
Cursor mqCur = managedQuery(myContacts, null, null, null, null);
if(mqCur.moveToFirst())
{
String myname = null;
String mynumber = null;
do
{
myname = mqCur.getString(mqCur.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
mynumber = mqCur.getString(mqCur
.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
Toast.makeText(this, myname + " " + mynumber, Toast.LENGTH_SHORT).show();
}
while(mqCur.moveToNext());
}
I think this will help you.
这篇关于进不去的Android 2.3.3电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!