0

the following is my code, it is showing a persons phone number type with radio button selection,but it is not showing the emails, i need to select the email also` public void GetContacts() { Log.i(classTag, "ContactsButton On Click"); Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);

         startActivityForResult(intent, 1);   
       // Log.i(classTag, "contactIntent:"+contactPickerIntent);



    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
         if (data != null) {
                Uri uri = data.getData();

                if (uri != null) {
                    Cursor c = null;
                    Cursor e=null;
                    try {


                         c = getContentResolver().query(uri, new String[]{ 
                                    ContactsContract.CommonDataKinds.Phone.NUMBER,  
                                    ContactsContract.CommonDataKinds.Phone.TYPE ,ContactsContract.CommonDataKinds.Email.DATA,ContactsContract.CommonDataKinds.Email.TYPE},
                                null, null, null);
                         String number=null;
                         int type=0;
                         String email=null;
                         String emailType=null;
                        if (c != null && c.moveToFirst()) {
                            number = c.getString(0);
                            as=number;
                           type = c.getInt(1);
                           email=c.getString(2);
                           emailType=c.getString(3);
                            Log.i(classTag, "type is:"+type);
                            Log.i(classTag, "email is:"+email);
                            Log.i(classTag, "emailtype is:"+emailType);
                           // showSelectedNumber(type, number);
                            TelephonyManager tMgr =(TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
                            String iso=tMgr.getNetworkCountryIso();
                            Log.i("Device iso", "=======>"+iso);
                            String mbNo=tMgr.getLine1Number();
                            Log.i("mbNo", "=======>"+mbNo);

                               PhoneNumberFormat(number);
                               Intent i=new Intent(Contact.this, Tab.class);
                               i.putExtra("key", number);
                               Contact.this.startActivityForResult(i, 0);
                        }
                        Cursor emails = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,null,ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + type,null, null);
                        Log.i(classTag, "emai:"+emails);
                        String emailAddress=null;
                        while (emails.moveToNext()) 
                        {
                        emailAddress =   emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
                         Log.i(classTag, "email is:"+emailAddress);
                        }
                     //  as=emailAddress;

                    } finally {
                        if (c != null) {
                            c.close();

                        }

                    }
            }
                }
}

1 Answers1

0

Visit this tutorial

http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/

and also

How to read contacts on Android 2.0

Community
  • 1
  • 1
kehnar
  • 1,387
  • 2
  • 12
  • 25
  • thank you chandan, but i worked with the link which u provide , still i am unable to provide mutiple selection of phone number and emails at time to edit in edittext, can you send me the working code , – srinivasa rao ramisetty Oct 18 '11 at 07:38