Sub LogAllContacts
'to use this example
'1. copy the attached jar and xml Files in your Library folder
'2. activate lib as usual.
Dim mu As miscUtil
mu.Initialize
Dim contacts As Map
Dim i As Int
contacts = mu.GetContactMap
For i = 0 To contacts.Size-1
Log(contacts.GetValueAt(i))
Next
End Sub
it does NOT list all contacts from contacts.
Optimist,
Would you mind to share that piece of code of the lib as source code?
I want to help you with this make it better than teh orginal one.
public class miscUtil {
private BA m_ba;
/**
* Common initialisations
*/
public void Initialize(BA ba) {
m_ba = ba;
}
/**
* Erzeut eine Map mit allen vorhandenen Kontakten
* Key ist eine ID, mit der weitere Kontaktinfos abgefragt werden können
*/
public Map GetContactMap() {
Map personen = new Map();
personen.Initialize();
Uri person = ContactsContract.Contacts.CONTENT_URI;
String[] person_projection = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME
};
Cursor person_cur = m_ba.activity.managedQuery(person, person_projection, null, null, null);
person_cur.moveToFirst();
while (person_cur.isAfterLast() == false) {
personen.Put(person_cur.getString(0), person_cur.getString(1));
person_cur.moveToNext();
}
person_cur.close();
return personen;
}
}
I get everytime a nullpointer.
public List GetContactList(){
List personenlist = new List();
personenlist.Initialize();
Uri personlist = ContactsContract.Contacts.CONTENT_URI;
String[] personlist_projection = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.HAS_PHONE_NUMBER,
};
Cursor cur = m_ba.activity.managedQuery(personlist, personlist_projection, null, null, null);
if (cur.getCount() > 0 ) {
cur.moveToFirst();
while (cur.isAfterLast() == false) {
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = m_ba.activity.managedQuery(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
new String[]{id}, null);
while (pCur.moveToNext()) {
String PhoneNum = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA1));
personenlist.Add(name + "=" + PhoneNum );
//personenlist.Add(PhoneNum);
}
pCur.close();
}
//personen.Put(person_cur.getString(0), person_cur.getString(1));
cur.moveToNext();
}
cur.close();
}
return personenlist;
}