get phone number in android
<p>I use this code to get phone no in android2.1.but i don't suceed please help me</p>

<p>public void onCreate(Bundle savedInstanceState) 
    {</p>

<pre><code>    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.makeText(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();


}
</code></pre>
