Hey guy, I'm trying to get the First Name, Last name and the Company of a
contact from a phone number. But unfortunately while doing so I'm getting
an exception.
My Code is as follows:
*Uri NameUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI,
Uri.encode(number));
String[] PROJECTION = new String[]
{ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Organization.COMPANY,
ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME };
ContentResolver contentResolver = getContentResolver();
contactLookup = contentResolver.query(NameUri, PROJECTION,
null, null, null);
if (contactLookup != null && contactLookup.getCount() > 0) {
contactLookup.moveToNext();
fName =
contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
organization =
contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.CommonDataKinds.Organization.COMPANY));
LName =
contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
// LName =
contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.));
//String contactId =
contactLookup.getString(contactLookup.getColumnIndex(BaseColumns._ID));
String full = fName+" "+LName+" "+organization;
Log.d("SMSAPPH", "THE LNAME, ORGANIZATION NAME AND FNAME
IS"+full);
System.out.println("-----------THE LNAME, ORGANIZATION NAME
AND FNAME IS-----------"+full);
}
}catch(Exception e){
e.printStackTrace();
}
finally {
if (contactLookup != null) {
contactLookup.close();
}
}*
The Exception stack trace is:
*03-19 18:05:28.476: W/System.err(12527): at
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:170)
03-19 18:05:28.476: W/System.err(12527): at
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
03-19 18:05:28.476: W/System.err(12527): at
android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
03-19 18:05:28.476: W/System.err(12527): at
android.content.ContentResolver.query(ContentResolver.java:372)
03-19 18:05:28.476: W/System.err(12527): at
android.content.ContentResolver.query(ContentResolver.java:315)
03-19 18:05:28.476: W/System.err(12527): at
com.msdsmsh.TheSMSOutgoingClass.populateContactDetails(TheSMSOutgoingClass.java:428)
03-19 18:05:28.481: W/System.err(12527): at
com.msdsmsh.TheSMSOutgoingClass$YourObserver.onChange(TheSMSOutgoingClass.java:197)
03-19 18:05:28.481: W/System.err(12527): at
android.database.ContentObserver.onChange(ContentObserver.java:129)
03-19 18:05:28.481: W/System.err(12527): at
android.database.ContentObserver$NotificationRunnable.run(ContentObserver.java:180)
03-19 18:05:28.486: W/System.err(12527): at
android.os.Handler.handleCallback(Handler.java:615)
03-19 18:05:28.486: W/System.err(12527): at
android.os.Handler.dispatchMessage(Handler.java:92)
03-19 18:05:28.486: W/System.err(12527): at
android.os.Looper.loop(Looper.java:137)
03-19 18:05:28.486: W/System.err(12527): at
android.app.ActivityThread.main(ActivityThread.java:4898)
03-19 18:05:28.486: W/System.err(12527): at
java.lang.reflect.Method.invokeNative(Native Method)
03-19 18:05:28.486: W/System.err(12527): at
java.lang.reflect.Method.invoke(Method.java:511)
03-19 18:05:28.486: W/System.err(12527): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-19 18:05:28.486: W/System.err(12527): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-19 18:05:28.486: W/System.err(12527): at
dalvik.system.NativeStart.main(Native Method)*
Could someone kindly help me with this?
Thanks
Ameya
--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.