I use this code to get phone no in android2.1.but i don't suceed please help me
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String contactId,name,number;
Cursor cursor=getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null,null,null,null);
cursor.moveToFirst();
if(cursor.moveToFirst())
{
do
{
contactId=cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
name=cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
number=cursor.getString(cursor.getColumnIndex(Phone.NUMBER));
int type=cursor.getInt(cursor.getColumnIndex(Phone.TYPE));
switch(type)
{
case Phone.TYPE_HOME :
Toast.makeText(this,"home--"+number+"",Toast.LENGTH_LONG).show();
break;
case Phone.TYPE_MOBILE :
Toast.makeText(this,"mobile--"+number+"",Toast.LENGTH_LONG).show();
break;
}
//Toast.开发者_如何学PythonmakeText(this,"ID--"+contactId+"name"+name+"number:"+number, Toast.LENGTH_LONG).show();
}while(cursor.moveToNext());
}
// Cursor phone=getContentResolver().query(Phone.CONTENT_URI,null,Phone.CONTACT_ID+"="+contactId,null,null);
//phone.close();
cursor.close();
}
http://www.androidsnippets.com/get-my-phone-number
private String getPhoneNumber(){ TelephonyManager __TelephonyManager; __TelephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); return mTelephonyMgr.getLine1Number(); }
精彩评论