i want to access contact details page using contact id.(which shown as image) i tried to do that but its loading contact list not the relevant contact details page.this is the interface what i want to access using relevant contact id.
i used this segment of code,
Uri contactPhotoUri = Uri.withAppendedPath(
ContactsContract.Contacts.CONTENT_URI,
String.valueOf(contact.getContactId()));
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
intent.setDataAndType(contactPhotoUri,
"vnd.android.cursor.dir/contact");
getActivity().startActivity(intent);
onActivityResult method,
ArrayList<Object> contactInfo = EntityUtils.getContact(reqCode,
resultCode, data, getActivity());
addContact(contactInfo);
getContact(),
@SuppressWarnings("deprecation")
public static ArrayList<Object> getContact(int reqCode, int resultCode, Intent data, FragmentActivity activity) {
Uri contactData = data.getData();
ArrayList<Object> contactInfo = null;
String email = null;
String officeEmail = null;
Cursor c = activity.managedQuery(contactData, null, null, null, null);
if (c.moveToFirst()) {
String id = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts._ID));
String hasPhone = c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
// String hasEmail = c
// .getString(c
// .getColumnIndex(ContactsContract.Contacts.));
String[] projection = new String[]{ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Email.DATA, ContactsContract.Contacts._ID, ContactsContract.CommonDataKinds.Phone.PHOTO_URI};
if (hasPhone.equalsIgnoreCase("1")) {
Cursor phones = activity.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + id, null, null);
// To get Email ids of Contact
Cursor emails = activity.getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, projection,
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", new String[]{id}, null);
phones.moveToFirst();
String cNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
String name = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
// String contactId = phones.getString(phones
// .getColumnIndex(ContactsContract.Contacts._ID));
String imageUri = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI));
while (emails.moveToNext()) {
email = emails.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
// officeEmail = emails
// .getString(phones
// .getColumnIndex(ContactsContract.CommonDataKinds.OrganizationEmail.DATA));
}
Bitmap imageBitmap = loadContactPhoto(activity.getContentResolver(), Long.parseLong(id));
// saveBitmapToFile(a);
// create contact
Contact contact = new Contact();
contact.setFirstName(name);
contact.setEmail(email);
contact.setOfficeEmail(officeEmail);
contact.setContactId(id);
contact.setImageUri(imageUri);
// create contactSourse
ContactSource cs = new ContactSource();
cs.setContactId(id);
cs.setData(cNumber);
cs.setType(email);
contactInfo = new ArrayList<Object>();
contactInfo.add(contact);
contactInfo.add(cs);
}
}
return contactInfo;
}
0 comments:
Post a Comment