Extension-Contact Library

madSac

Active Member
Licensed User
Longtime User
I am hanged up in another problem.
I want to get first name, last name differently but in all present libraries we can retrieve full Name.And splitting a name cannot help.So please add following fields
First Name
Middle Name
Surname
Postal Address
Website
Birthday
Anniversary
Mainly i need is First name and last name...If it is possible using reflection then also its fine.I have persons ID as identification.
Thank you...
 

Theera

Well-Known Member
Licensed User
Longtime User
Try use Erel's KeyStoreValue. You could search it the Right-top of IDE
 
Upvote 0

madSac

Active Member
Licensed User
Longtime User
Hi madSac,

try with this Library

Ciao,
Filippo
Hey Filippo,

This lib does not satisfies my need completely .I have tried it before.I think this is your library so i have a code suggestion for you
B4X:
Context context;
   @SuppressWarnings("static-access")
   public String[] readContacts(BA ba,int tmp){
      context=ba.context;
      ContentResolver cr = context.getContentResolver();
      Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", new String[]{"36"}, null);
      String data[] = new String[cur.getCount()];
      if (cur.getCount() > 0) {
         //=new mcontact[cur.getCount()];
         
         while (cur.moveToNext()) {
            /*
            data[i] = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
             String id=data[i].ID;
            // data[i][1] = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            //string firstname= cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.));
            if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
               //ba.Log("name : " + name + ", ID : " + id); 
               // get the phone number 
               Cursor pCur = cr.query(   ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                     null,
                     ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", new String[]{id},
                     null
                     ); 
      
               while (pCur.moveToNext()) {
                  String phone = pCur.getString( pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                  //ba.Log("phone" + phone);
                  } 
               pCur.close(); 
               // get email and type
               Cursor emailCur = cr.query( ContactsContract.CommonDataKinds.Email.CONTENT_URI,
                     null,
                     ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", new String[]{id},
                     null
                     );
               while (emailCur.moveToNext()) { 
                  // This would allow you get several email addresses
                  // if the email addresses were stored in an array 
                  String email = emailCur.getString( emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
                  String emailType = emailCur.getString( emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE)); 
                  ba.Log("Email " + email + " Email Type : " + emailType); 
                  } 
               emailCur.close(); 
               // Get note....... 
               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
                     ); 
               if (noteCur.moveToFirst()) {
                  String note = noteCur.getString(noteCur.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE)); 
                  ba.Log("Note " + note); 
                  } 
               noteCur.close(); 
               //Get Postal Address.... 
               String addrWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; 
               String[] addrWhereParams = new String[]{id, ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE}; 
               Cursor addrCur = cr.query(ContactsContract.Data.CONTENT_URI,
                     null,
                     null,
                     null,
                     null
                     ); 
               while(addrCur.moveToNext()) {
                  String poBox = addrCur.getString( addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POBOX)); 
                  String street = addrCur.getString( addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.STREET));
                  String city = addrCur.getString( addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.CITY)); 
                  String state = addrCur.getString( addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.REGION));
                  String postalCode = addrCur.getString( addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE)); 
                  String country = addrCur.getString( addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY));
                  String type = addrCur.getString( addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.TYPE)); 
                  // Do something with these.... 
                  } addrCur.close(); 
                  // Get Instant Messenger......... 
                  String imWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
                  String[] imWhereParams = new String[]{id, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE};
                  Cursor imCur = cr.query(ContactsContract.Data.CONTENT_URI,
                        null,
                        imWhere,
                        imWhereParams,
                        null
                        ); 
                  if (imCur.moveToFirst()) { 
                     String imName = imCur.getString( imCur.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)); 
                     String imType; imType = imCur.getString( imCur.getColumnIndex(ContactsContract.CommonDataKinds.Im.TYPE));
                     }
                  imCur.close();
                  // Get Organizations......... 
                  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
                        );
                  if (orgCur.moveToFirst()) { 
                     String orgName = orgCur.getString(orgCur.getColumnIndex(ContactsContract.CommonDataKinds.Organization.DATA));
                     String title = orgCur.getString(orgCur.getColumnIndex(ContactsContract.CommonDataKinds.Organization.TITLE));
                     } 
                  orgCur.close();
                  }
               */
            }
         }
      return data;
      }
Can you please add...Currently i don't have enough time to play with error..Although it has less errors.

I have commented out the MAIN Section as i was playing with it
You will be getting many field in this class
B4X:
ContactsContract.CommonDataKinds.StructuredName

Please do it as soon as possible...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…