Get actual Contact name from phone number - android

Suppose I have created a Contact with blank name ("") and entered 2 number
1234
5678
Now I want to retrieve name from this 2 number. My code always gets first number as name if name is empty. How can I get actual name?
I have used this code:
public static String getContactNamefromNumber(Context context,
String contactNumber) {
if (contactNumber == null || contactNumber.equals(""))
return null;
String name = null;
Cursor contactLookupCursor = context.getContentResolver().query(
Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(contactNumber)),
new String[] { PhoneLookup.DISPLAY_NAME, PhoneLookup._ID},
null, null, null);
if (contactLookupCursor != null) {
if (contactLookupCursor.moveToFirst()) {
do {
name = contactLookupCursor.getString(contactLookupCursor
.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME));
} while (contactLookupCursor.moveToNext());
}
contactLookupCursor.close();
}
return name;
}
This code always give me first number as name if actual contact name is blank. I want the actual name( it may blank or valid name) not number. If there is anyway to determine name is blank ? this will also solve my problem.
Added:
I also tried below code:
String name ="";
Cursor nameCur = context.getContentResolver()
.query(ContactsContract.Data.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.StructuredName.CONTACT_ID + " = ?",
new String[] {
Long.valueOf(contactId).toString() }, null);
if (nameCur != null && nameCur.getCount() > 0 ) {
nameCur.moveToFirst();
do {
name += "" + nameCur.getPosition() + " : ";
String displayName = nameCur.getString(nameCur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (displayName == null) displayName = "";
String firstName = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
if (firstName == null) firstName = "";
String middleName = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME));
if (middleName == null) middleName = "";
String lastName = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
if (lastName == null) lastName = "";
name += "First: " + firstName + " Middle: " + middleName + " Last: " + lastName + "\n";
}while (nameCur.moveToNext());
nameCur.close();
}
Here i have used contactid to load name but not working for all contacts. For some contacts nameCur contain more than one rows(2,3,4,...8 etc). And sometime first row contains blank info . Here is a sample info i get form nameCur. For below case i got nameCur with size 9.
0 : First: Middle: Last:
1 : First: Test_Name Middle: Last: Deb
2 : First: Middle: Last:
3 : First: Middle: Last:
4 : First: Middle: Last:
5 : First: 3 Middle: Last:
6 : First: com.google Middle: Last:
7 : First: Middle: Last:
8 : First: 2 Middle: Last:

You can try
String given = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
String family = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));

I have solved this with some modification. I have added where clause
ContactsContract.Data.MIMETYPE = ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE
and sort order
ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME
Here is the code i have used:
public static String getActualContactNameByContactId(Context context, long contactId){
String name ="";
String whereName = ContactsContract.CommonDataKinds.StructuredName.CONTACT_ID + " = ? " + " AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] whereNameParams = new String[] { String.valueOf(contactId), ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE };
String sortOrder = ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME;
// get firstName & lastName
Cursor nameCur = context.getContentResolver()
.query(ContactsContract.Data.CONTENT_URI,
null,
whereName,
whereNameParams,
sortOrder);
if (nameCur != null && nameCur.getCount() > 0 ) {
nameCur.moveToFirst();
try {
nameCur.getString(nameCur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
// if (displayName == null) displayName = "";
String firstName = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
if (firstName == null) firstName = "";
//Log.d("--> ", firstName.length()>0?firstName:displayName);
String middleName = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME));
if (middleName == null) middleName = "";
String lastName = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
if (lastName == null) lastName = "";
name = firstName.trim();
if (middleName.trim().length() > 0) {
if (name.length() > 0) {
name+= " ";
}
name+= middleName.trim();
}
if (lastName.trim().length() > 0) {
if (name.length() > 0) {
name+= " ";
}
name+= lastName.trim();
}
}catch (Exception e){
}finally {
nameCur.close();
}
}
return name;
}
I have taken only the first row form the cursor as multiple row may return.

Related

How to remove duplicate contact number from all type of contact without database?

How to remove duplicate number entry in Android when fetching contact number from contact book?
For example:
In contact book for
one name multiple contact.. ex-type-home-9428060123,
type-work-9428060123, I want to fetch unique contact number from all
type,android problematically? I use below code for fetching
information:
private void getContactsDetails() {
showLoader();
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '"
+ ("1") + "'";
Cursor phones = getActivity().getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null, null/*selection + " AND " +
ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1"*/, null, "UPPER("
+ ContactsContract.Contacts.DISPLAY_NAME + ") ASC");
ContactString = new ArrayList<>();
if (phones != null) {
if (phones.getCount() > 0) {
tvNoContact.setVisibility(View.GONE);
while (phones.moveToNext()) {
String Name = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String number = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
HashSet<String> mobileNoSet = new HashSet<String>();
if (!mobileNoSet.contains(number)){
String s = number.replaceAll("\\W", "");
String lastTenCharContact = null;
if (s != null && s.length() > 10) {
lastTenCharContact = s.substring(s.length() - 10);
} else {
lastTenCharContact = s;
}
// String substring = s.substring(Math.max(s.length() - 10, 0));
Log.d(TAG, "getContactsDetails: " + lastTenCharContact);
String image_uri = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI));
ContactString.add(lastTenCharContact);
DeviceContact contactModel = new DeviceContact(Name.toUpperCase(), lastTenCharContact, image_uri);
contactModelsList.add(contactModel);
mobileNoSet.add(number);
Log.d(TAG, "Name : " + Name + ", Number : " + number + ", Photo : " + image_uri);}
}
hideLoader();
AllContactsyncapiCall();
} else {
tvNoContact.setVisibility(View.VISIBLE);
}
} }
for remove duplicate Number just make hashset before your loop:
HashSet<String> mobileNoSet = new HashSet<String>();
Now when you put contact in model use below code:
if (!mobileNoSet.contains(number)){
String s = number.replaceAll("\\W", "");
String lastTenCharContact = null;
if (s != null && s.length() > 10) {
lastTenCharContact = s.substring(s.length() - 10);
} else {
lastTenCharContact = s;
}
// String substring = s.substring(Math.max(s.length() - 10, 0));
Log.d(TAG, "getContactsDetails: " + lastTenCharContact);
String image_uri = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI));
ContactString.add(lastTenCharContact);
DeviceContact contactModel = new DeviceContact(Name.toUpperCase(), lastTenCharContact, image_uri);
contactModelsList.add(contactModel);
mobileNoSet.add(number);
}
This is new code in which i m getting duplicate number :-
private void getContactsDetails() {
// showLoader();
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null/*selection + " AND " + ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1"*/, null, "UPPER(" + ContactsContract.Contacts.DISPLAY_NAME + ") ASC");
ContactString = new ArrayList<>();
nameString = new ArrayList<>();
if (phones != null) {
if (phones.getCount() > 0) {
tvNoContact.setVisibility(View.GONE);
HashSet<String> mobileNoSet = new HashSet<String>();
while (phones.moveToNext()) {
String Name = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String number = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
if (!mobileNoSet.contains(number)) {
// String s = number.replaceAll("\\W", "");
String s = number.replaceAll("[^[+]\\d]", "");
String lastTenCharContact = null;
lastTenCharContact = s;
/*if (s != null && s.length() > 10) {
lastTenCharContact = s.substring(s.length() - 10);
} else {
lastTenCharContact = s;
}*/
// String substring = s.substring(Math.max(s.length() - 10, 0));
Log.d(TAG, "getContactsDetails: " + lastTenCharContact);
String image_uri = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI));
ContactString.add(lastTenCharContact);
// nameString.add(Name);
contactModel = new DeviceContact(Name.toUpperCase(), lastTenCharContact, image_uri);
contactModelsList.add(contactModel);
mobileNoSet.add(number);
Log.d(TAG, "Name : " + Name + ", Number : " + number + ", Photo : " + image_uri);
}
}
// hideLoader();
AllContactsyncapiCall();
} else {
tvNoContact.setVisibility(View.VISIBLE);
}
}
}

Getting specific contact information

I'm trying to get the given name, family name etc of a specific contact on android but can't seem to be able to. I've been banging my head on this for hours, basically if (nameCur.moveNext()) is always false! This code is originally by #perborin (How to get the first name and last name from Android contacts?). Please help!
P.S. I've added <uses-permission android:name="android.permission.READ_CONTACTS"/> in the AndroidManifest, so that is not the problem.
// A contact ID is fetched from ContactList
Uri resultUri = data.getData();
Cursor cont = getContentResolver().query(resultUri, null, null, null, null);
if (!cont.moveToNext()) {
Toast.makeText(this, "Cursor contains no data", Toast.LENGTH_LONG).show();
return;
}
int columnIndexForId = cont.getColumnIndex(ContactsContract.Contacts._ID);
String contactId = cont.getString(columnIndexForId);
// Fetch contact name with a specific ID
String whereName = ContactsContract.Data.MIMETYPE + " = ? AND " + ContactsContract.CommonDataKinds.StructuredName.CONTACT_ID + " = " + contactId;
String[] whereNameParams = new String[] { ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE };
Cursor nameCur = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, whereName, whereNameParams, ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME);
while (nameCur.moveToNext()) {
String given = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
String family = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
String display = nameCur.getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME));
Toast.makeText(this, "Name: " + given + " Family: " + family + " Displayname: " + display, Toast.LENGTH_LONG).show();
}
nameCur.close();
cont.close();
Solved by referring to user3717188 answer at Get first and last name of a contact rather than single display name?.
Cursor phone_cursor = cr.query(ContactsContract.CommonDataKinds.
Phone.CONTENT_URI, null, null, null, null);
while (phone_cursor.moveToNext()) {
try {
int id = Integer.parseInt(phone_cursor.getString(phone_cursor.getColumnIndex
(ContactsContract.CommonDataKinds.Phone.CONTACT_ID)));
Cursor name_cursor = cr.query(ContactsContract.Data.CONTENT_URI,null,
ContactsContract.Data.CONTACT_ID + " = " + id, null, null);
String name = phone_cursor.getString(phone_cursor.getColumnIndex
(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String first_name ="";
String last_name = "";
while (name_cursor.moveToNext()) {
if(name_cursor.getString(name_cursor.getColumnIndex
(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME))!=null){
first_name = name_cursor.getString(name_cursor.getColumnIndex
(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
last_name = name_cursor.getString(name_cursor.getColumnIndex
(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
}}
name_cursor.close();
String phoneNumber = phone_cursor.getString(phone_cursor.getColumnIndex
(ContactsContract.CommonDataKinds.Phone.NUMBER));
} catch (Exception e) {
}
}
phone_cursor.close();

How to edit existing Contacts in Android?

I am trying to edit existing phone contacts by using application. By using contact name am getting the corresponding contact id.Then am trying to update the existing contacts by using the contact id. But unfortunately it is not updating.
My code is as follows,
String select = "(" + ContactsContract.Contacts.DISPLAY_NAME + " == \"" + edt_nameDetail.getText() + "\" )";
Cursor c = getActivity().getApplicationContext().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, CONTACTS_SUMMARY_PROJECTION, select, null, ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
getActivity().startManagingCursor(c);
if (c.moveToNext()) {
ContactId = c.getString(0);
Log.e("Tag contact id ","edit contact id "+ ContactId);
}
try
{
String name = edt_nameDetail.getText().toString().trim();
String email = edt_contactEmailDetail.getText().toString().trim();
String number = edt_mobileNumberDetail.getText().toString().trim();
ContentResolver contentResolver = getActivity().getContentResolver();
String where = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] emailParams = new String[]{ContactId, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE};
String[] nameParams = new String[]{ContactId, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE};
String[] numberParams = new String[]{ContactId, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE};
ArrayList<android.content.ContentProviderOperation> ops = new ArrayList<android.content.ContentProviderOperation>();
if(!email.equals("") &&!name.equals("")&& !number.equals(""))
{
ops.add(android.content.ContentProviderOperation.newUpdate(android.provider.ContactsContract.Data.CONTENT_URI)
.withSelection(where,emailParams)
.withValue(ContactsContract.CommonDataKinds.Email.DATA, email)
.build());
ops.add(android.content.ContentProviderOperation.newUpdate(android.provider.ContactsContract.Data.CONTENT_URI)
.withSelection(where,nameParams)
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name)
.build());
ops.add(android.content.ContentProviderOperation.newUpdate(android.provider.ContactsContract.Data.CONTENT_URI)
.withSelection(where,numberParams)
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, number)
.build());
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
Toast.makeText(getActivity(), "Contact is successfully edited", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getActivity(), "Fail edit", Toast.LENGTH_SHORT).show();
}
If you are searching with email then update your .withSelection as
.withSelection(ContactsContract.CommonDataKinds.Email.ADDRESS + "=? AND " +
Data.MIMETYPE + "='" +
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE + "'",
new String[]{email})
update all your withselection code corresponding to your search type
Note: after this, contact ID will changed.
public static boolean updateContactName(String contactId, String pre, String first, String mid, String last, String suf)
{
try
{
if (pre == null && first == null && mid == null && last == null && suf == null)
return false;
String where = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] nameParams = new String[]{contactId, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE};
ArrayList<android.content.ContentProviderOperation> ops = new ArrayList<>();
android.content.ContentProviderOperation.Builder t ;
android.content.ContentProviderOperation b ;
t = android.content.ContentProviderOperation.newUpdate(Data.CONTENT_URI);
t = t.withSelection(where, nameParams);
if(pre != null)
t = t.withValue(StructuredName.PREFIX, pre.trim());
if(first != null)
t = t.withValue(StructuredName.GIVEN_NAME, first.trim());
if(mid != null)
t = t.withValue(StructuredName.MIDDLE_NAME, mid.trim());
if(last != null)
t = t.withValue(StructuredName.FAMILY_NAME, last.trim());
if(suf != null)
t = t.withValue(StructuredName.SUFFIX, suf.trim());
b = t.build();
ops.add(b);
ContentManager.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
return true;
}
catch (Exception e) {}
return false;
}

Android sqlite select statement does not work well

I've got three table and i want make a query withe sql statement, but it does not work well because it does not give me all the possible results...
The code:
public void setsuchresultat(String pSearchword)
{
String[] table = new String[]{"tbl_A", "tbl_B", "tbl_C"};
String[] column = new String[]{"columnA", "columnB" }; // Type varchar(50) not null
String[] search = new String[]{"%" + pSearchword+ "%", pSearchword+ "%", "%" + pSearchword, pSearchword};
getdata(table,column,search);
}
public void getdata(String[] pTable, String[] pColumn, String[] pSearch)
{
for(String t:pTable)
{
for(String s : pColumn)
{
for(String k : pSearch)
{
Cursor c = this.db.rawQuery("SELECT * FROM " + t + " WHERE " + s + " LIKE '"+ k + "'", null);
if ((c.moveToFirst()) || c.getCount() > 0)
{
while(c.moveToNext())// Suchresultat abspeichern
{
String col1 = c.getString(c.getColumnIndex("columnA"));
String col2 = c.getString(c.getColumnIndex("columnB"));
}
}
}
}
}
}
I think problem is in your loop and if check.
Change
if ((c.moveToFirst()) || c.getCount() > 0)
{
while(c.moveToNext())// Suchresultat abspeichern
{
String col1 = c.getString(c.getColumnIndex("columnA"));
String col2 = c.getString(c.getColumnIndex("columnB"));
}
}
to
if (c.moveToFirst() || c.getCount() > 0) /* OR if (c != null && c.moveToFirst())*/ {
do {
String col1 = c.getString(c.getColumnIndex("columnA"));
String col2 = c.getString(c.getColumnIndex("columnB"));
} while(c.moveToNext());
}

Fetch contact list along with their primary email and phone number in a single query from the ContactProvider

I am trying to get the list of contacts with their phone and email details to display them in a list. What i have done now is do three separate queries.
Get list of contacts to contactCursor from Contacts.CONTENT_URI
Get all phone numbers to phoneCursor from Phone.CONTENT_ITEM_TYPE
Get all emails to emailCursor from Email.CONTENT_ITEM_TYPE
Then i will am Looping through the contactCursor. For every contact, i will loop through the phoneCursor and emailCursor to get the primary phone number and email. But this takes some time to load and is clearly visible when the number of contacts is large. Is there any way that i can get all these details in the first step itself.
Below is the code snippet:
Cursor contacts = resolver.query(Contacts.CONTENT_URI,
CONTACT_PROJECTION, Contacts.HAS_PHONE_NUMBER + " != 0", null, Contacts._ID + " ASC");
Cursor phone = resolver.query(Data.CONTENT_URI, PHONE_PROJECTION,
Data.MIMETYPE + "=? ",
new String[]{Phone.CONTENT_ITEM_TYPE},
Data.CONTACT_ID + " ASC");
Cursor email = resolver.query(Data.CONTENT_URI, EMAIL_PROJECTION,
Data.MIMETYPE + "=? ",
new String[]{Email.CONTENT_ITEM_TYPE},
Data.CONTACT_ID + " ASC");
if (contacts!=null && contacts.moveToFirst()) {
do {
String contactId = contacts.getString(0);
if(phone!=null && phone.moveToFirst()){
do{
if(contactId.equalsIgnoreCase(phone.getString(0))){
contact.setMobile(phone.getString(1));
break;
}
}while(phone.moveToNext());
}
if(email!=null && email.moveToFirst()){
do{
if(contactId.equalsIgnoreCase(email.getString(2))){
contact.setEmailWork(email.getString(1));
break;
}
}while(email.moveToNext());
}
} while (contacts.moveToNext());
Below is the code to fetch all the contacts including email.
private void getContacts() {
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
String id = null, name = null, email = null, phone = null, note = null, orgName = null, title = null;
String Phone1 = "unknown", Phone2 = "unknown", Phone3 = "unknown", type1 = "unknown", type2 = "unknown", type3 = "unknown";
int size = cur.getCount();
StringBuilder addbuffer = null;
if (cur.getCount() > 0) {
int cnt = 1;
while (cur.moveToNext()) {
email = "";
name = "";
cnt++;
id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (name != null && name != "") {
// if (!checkEmail(name)) {
// email = "";
//
// } else {
email = name;
name = "";
// }
}
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
System.out.println("name : " + name);
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[] { id }, null);
Phone1 = " ";
Phone2 = " ";
Phone3 = " ";
while (pCur.moveToNext()) {
String phonetype = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
String MainNumber = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
if (phonetype.equalsIgnoreCase("1")) {
Phone1 = MainNumber;
type1 = "home";
} else if (phonetype.equalsIgnoreCase("2")) {
Phone2 = MainNumber;
type2 = "mobile";
} else {
Phone3 = MainNumber;
type3 = "work";
}
}
pCur.close();
}
Cursor addrCur = cr.query(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI, null, ContactsContract.CommonDataKinds.StructuredPostal.CONTACT_ID
+ " = ?", new String[] { id }, null);
if (addrCur.getCount() == 0) {
addbuffer.append("unknown");
} else {
int cntr = 0;
while (addrCur.moveToNext()) {
cntr++;
String poBox = addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POBOX));
if (poBox == null) {
poBox = " ";
}
String street = addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.STREET));
if (street == null) {
street = " ";
}
String neb = addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.NEIGHBORHOOD));
if (neb == null) {
neb = " ";
}
String city = addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.CITY));
if (city == null) {
city = " ";
}
String state = addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.REGION));
if (state == null) {
state = " ";
}
String postalCode = addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE));
if (postalCode == null) {
postalCode = " ";
}
String country = addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY));
if (country == null) {
country = " ";
}
String type = addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.TYPE));
if (type == null) {
type = " ";
}
}
}
addrCur.close();
String noteWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] noteWhereParams = new String[] { id, ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE };
Cursor noteCur = cr.query(ContactsContract.Data.CONTENT_URI, null, noteWhere, noteWhereParams, null);
note = " ";
if (noteCur.moveToFirst()) {
note = noteCur.getString(noteCur.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE));
if (note == null) {
note = " ";
}
}
noteCur.close();
String orgWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] orgWhereParams = new String[] { id, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE };
Cursor orgCur = cr.query(ContactsContract.Data.CONTENT_URI, null, orgWhere, orgWhereParams, null);
orgName = " ";
if (orgCur.moveToFirst()) {
orgName = orgCur.getString(orgCur.getColumnIndex(ContactsContract.CommonDataKinds.Organization.COMPANY));
}
if (orgName == null) {
orgName = " ";
}
orgCur.close();
Cursor emailCur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",
new String[] { id }, null);
email = "unknown";
while (emailCur.moveToNext()) {
email = emailCur.getString(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
String emailType = emailCur.getString(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));
if (email == null) {
email = "unknown";
}
if (emailType.equalsIgnoreCase("1")) {
} else {
}
}
// add
emailCur.close();
}
}
}

Categories

Resources