Open the contacts\Phone Book API

Put your problem here if it does not fit any of the other categories.

Open the contacts\Phone Book API

Postby robybd » Sun Mar 21, 2010 10:18 am

Hello,

In my application I would like to have a button, for example, "Choose from contact"
and once the user will press it, i'll show him the contacts on his phone\SIM.
I'm familiar with the ContactsContract API but i didn't find a method that will prompt the user with
all available contacts so when he chooses one of them i'll get in response the index\contact details.

Can someone point me to the correct method (QuickContact?)?
Thanks.
robybd
Developer
Developer
 
Posts: 31
Joined: Mon Mar 01, 2010 9:10 am

Top

Postby asolanki » Mon Mar 22, 2010 10:23 am

Hi!!!

may be you can use contentprovider and access contacts database...

by contentprovider you will get curser to the phonebook database
asolanki
Senior Developer
Senior Developer
 
Posts: 151
Joined: Thu Jan 08, 2009 7:32 am

Postby robybd » Mon Mar 22, 2010 10:51 am

Hi,

That's the exact thing i'm trying to avoid, i would like to use the native Phonebook of Android and once the user will select a name\phone i'll get either the index or the entry which he chose.
Are you familiar with such API?

Thanks.
robybd
Developer
Developer
 
Posts: 31
Joined: Mon Mar 01, 2010 9:10 am

Postby vik » Tue Mar 23, 2010 6:20 am

startActivityForResult(new Intent(Intent.ACTION_PICK, People.CONTENT_URI), 0);

his might solve your problem
User avatar
vik
Senior Developer
Senior Developer
 
Posts: 141
Joined: Wed Sep 09, 2009 7:32 am

Postby pranav09 » Wed Mar 24, 2010 11:47 am

Hi robybd,

Just have a look at below code. The below code finds the contacts from the phone(I have not actual device. So, weather it finds from SIM card or not that i don't know). The code is tested on SDK 2.0 as well as on SDK 2.0.1. I hope you will get the solution.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.        
  2.  
  3.         ContentResolver contentResolver;
  4.  
  5.         Cursor cursor;
  6.  
  7.         String id, name;
  8.  
  9.         contentResolver = getContentResolver();
  10.  
  11.         cursor = contentResolver.query(Contacts.People.CONTENT_URI, null, null, null, null);
  12.  
  13.              if (cursor.getCount() > 0)
  14.  
  15.              {
  16.  
  17.                 while (cursor.moveToNext())
  18.  
  19.                 {
  20.  
  21.                      id = cursor.getString(cursor.getColumnIndex(Contacts.People._ID));
  22.  
  23.                      System.out.println("ID: "+id);
  24.  
  25.                      name = cursor.getString(cursor.getColumnIndex(Contacts.People.DISPLAY_NAME));
  26.  
  27.                      System.out.println("Name: "+name);
  28.  
  29.                 }
  30.  
  31.              }
  32.  
  33.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


The below code helps you out to open in-built Create New Contact functionality of phone. Just put this code on the action listener of the button.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                 Intent i=new Intent(Intent.ACTION_INSERT_OR_EDIT);
  3.  
  4.                 i.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
  5.  
  6.                 i.putExtra(Insert.NAME, "Pranav");
  7.  
  8.                 startActivity(i);
  9.  
  10.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


That's all.
Hope its help you out.

Thanks.

Regards,
________________
Pranav
User avatar
pranav09
Senior Developer
Senior Developer
 
Posts: 128
Joined: Mon Jan 19, 2009 12:01 pm
Location: Ahmedabad, India

Postby pranav09 » Wed Mar 24, 2010 12:02 pm

Hi robybd,

Just have a look at below code. The below code finds the contacts from the phone(I have not actual device. So, weather it finds from SIM card or not that i don't know). The code is tested on SDK 2.0 as well as on SDK 2.0.1. I hope you will get the solution.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.        
  2.  
  3.         ContentResolver contentResolver;
  4.  
  5.         Cursor cursor;
  6.  
  7.         String id, name;
  8.  
  9.         contentResolver = getContentResolver();
  10.  
  11.         cursor = contentResolver.query(Contacts.People.CONTENT_URI, null, null, null, null);
  12.  
  13.              if (cursor.getCount() > 0)
  14.  
  15.              {
  16.  
  17.                 while (cursor.moveToNext())
  18.  
  19.                 {
  20.  
  21.                      id = cursor.getString(cursor.getColumnIndex(Contacts.People._ID));
  22.  
  23.                      System.out.println("ID: "+id);
  24.  
  25.                      name = cursor.getString(cursor.getColumnIndex(Contacts.People.DISPLAY_NAME));
  26.  
  27.                      System.out.println("Name: "+name);
  28.  
  29.                 }
  30.  
  31.              }
  32.  
  33.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


The below code helps you out to open in-built Create New Contact functionality of phone. Just put this code on the action listener of the button.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                 Intent i=new Intent(Intent.ACTION_INSERT_OR_EDIT);
  3.  
  4.                 i.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
  5.  
  6.                 i.putExtra(Insert.NAME, "Pranav");
  7.  
  8.                 startActivity(i);
  9.  
  10.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


That's all.
Hope its help you out.

Thanks.

Regards,
________________
Pranav
User avatar
pranav09
Senior Developer
Senior Developer
 
Posts: 128
Joined: Mon Jan 19, 2009 12:01 pm
Location: Ahmedabad, India

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests