[android-developers] reading contacts...

2010-10-26 Thread A N K ! T
while am trying to pick a contact from phone book it is returning another
contact...
i dont know what happening..
this is my code

.//*contactData is uri getting from onActivity result*

*String[] parts = contactData.toString().split(/);
long id = Long.parseLong(parts[parts.length - 1]);
Uri rawContactUri =
ContentUris.withAppendedId(RawContacts.CONTENT_URI,
id);
Uri entityUri = Uri.withAppendedPath(rawContactUri,
Entity.CONTENT_DIRECTORY);

Cursor c = activity
.managedQuery(
entityUri,
new String[] { Entity.MIMETYPE, Entity.DATA1,
Phone.TYPE },
Entity.MIMETYPE + =? OR  + Entity.MIMETYPE + =?,
new String[] {

ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,

ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE },
null);
String NumbersData[][] = new String[c.getCount() - 1][2];
number_type = new String[c.getCount() - 1];
if (c.moveToFirst()) {
do {
String mimeType = c.getString(0);


if (mimeType

.equals(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE))
{
NAME = c.getString(1);
Log.d(TAG, Name:  + NumbersData);
} else if (mimeType

.equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
NumbersData[i][0] = c.getString(2);// this is
number type
NumbersData[i][1] = c.getString(1);  //this is the
number
i++;
Log.d(TAG, Phone:  + NumbersData);
}
} while (c.moveToNext());*

-- 

 A N K ! T..

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] reading contacts...

2010-10-26 Thread Prakash Iyer
You might be using the contact id as id of raw contact. Isn't clear that's
the problem as I didn't bother to go thru your logic for contactData but
that would result in a problem like what you are describing...
On Oct 26, 2010 7:40 AM, A N K ! T ankit.awasth...@gmail.com wrote:
 while am trying to pick a contact from phone book it is returning another
 contact...
 i dont know what happening..
 this is my code

 .//*contactData is uri getting from onActivity result*

 *String[] parts = contactData.toString().split(/);
 long id = Long.parseLong(parts[parts.length - 1]);
 Uri rawContactUri =
 ContentUris.withAppendedId(RawContacts.CONTENT_URI,
 id);
 Uri entityUri = Uri.withAppendedPath(rawContactUri,
 Entity.CONTENT_DIRECTORY);

 Cursor c = activity
 .managedQuery(
 entityUri,
 new String[] { Entity.MIMETYPE, Entity.DATA1,
 Phone.TYPE },
 Entity.MIMETYPE + =? OR  + Entity.MIMETYPE + =?,
 new String[] {

 ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,

 ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE },
 null);
 String NumbersData[][] = new String[c.getCount() - 1][2];
 number_type = new String[c.getCount() - 1];
 if (c.moveToFirst()) {
 do {
 String mimeType = c.getString(0);


 if (mimeType


.equals(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE))
 {
 NAME = c.getString(1);
 Log.d(TAG, Name:  + NumbersData);
 } else if (mimeType

 .equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
 NumbersData[i][0] = c.getString(2); // this is
 number type
 NumbersData[i][1] = c.getString(1); //this is the
 number
 i++;
 Log.d(TAG, Phone:  + NumbersData);
 }
 } while (c.moveToNext());*

 --

 A N K ! T..

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] reading contacts...

2010-10-26 Thread A N K ! T
am using this way to get _id of selected contact

String column[]={RawContacts._ID};
Cursor temp=activity.managedQuery(contactData, column, null, null,
null);
  if(temp.moveToFirst())
  {  id=temp.getLong(0);}

and then creating rawContacturi...

Uri rawContactUri =
ContentUris.withAppendedId(RawContacts.CONTENT_URI,
id);

On Tue, Oct 26, 2010 at 5:25 PM, Prakash Iyer thei...@gmail.com wrote:

 You might be using the contact id as id of raw contact. Isn't clear that's
 the problem as I didn't bother to go thru your logic for contactData but
 that would result in a problem like what you are describing...
 On Oct 26, 2010 7:40 AM, A N K ! T ankit.awasth...@gmail.com wrote:
  while am trying to pick a contact from phone book it is returning another
  contact...
  i dont know what happening..
  this is my code
 
  .//*contactData is uri getting from onActivity result*
 
  *String[] parts = contactData.toString().split(/);
  long id = Long.parseLong(parts[parts.length - 1]);
  Uri rawContactUri =
  ContentUris.withAppendedId(RawContacts.CONTENT_URI,
  id);
  Uri entityUri = Uri.withAppendedPath(rawContactUri,
  Entity.CONTENT_DIRECTORY);
 
  Cursor c = activity
  .managedQuery(
  entityUri,
  new String[] { Entity.MIMETYPE, Entity.DATA1,
  Phone.TYPE },
  Entity.MIMETYPE + =? OR  + Entity.MIMETYPE + =?,
  new String[] {
 
  ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,
 
  ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE },
  null);
  String NumbersData[][] = new String[c.getCount() - 1][2];
  number_type = new String[c.getCount() - 1];
  if (c.moveToFirst()) {
  do {
  String mimeType = c.getString(0);
 
 
  if (mimeType
 
 
 .equals(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE))
  {
  NAME = c.getString(1);
  Log.d(TAG, Name:  + NumbersData);
  } else if (mimeType
 
  .equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
  NumbersData[i][0] = c.getString(2); // this is
  number type
  NumbersData[i][1] = c.getString(1); //this is the
  number
  i++;
  Log.d(TAG, Phone:  + NumbersData);
  }
  } while (c.moveToNext());*
 
  --
 
  A N K ! T..
 
  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/android-developers?hl=en

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




-- 

 A N K ! T..

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Reading contacts

2010-05-07 Thread EPecorari
Hi,
I'm trying to read all the contacts stored in the phone using this
code:

Cursor cursorNumber =
context.getContentResolver().query( Contacts.Phones.CONTENT_URI,
new String[]
{ Contacts.Phones._ID, Contacts.Phones.NAME,
Contacts.Phones.NUMBER }, null, null, null );

but the result seems empty until the moment I sync the contacts with
Google. Is that possible? Is it a limitation of Google Contacts API?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en