2009-10-01 06:34:28 +08:00
|
|
|
package com.phonegap.demo;
|
|
|
|
|
|
|
|
import android.provider.Contacts.People;
|
2009-11-03 07:43:09 +08:00
|
|
|
import android.app.Activity;
|
2009-10-10 01:23:21 +08:00
|
|
|
import android.content.ContentResolver;
|
2009-10-01 06:34:28 +08:00
|
|
|
import android.content.ContentUris;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
|
|
|
public class ContactManager {
|
2009-11-03 07:43:09 +08:00
|
|
|
|
|
|
|
Activity mApp;
|
|
|
|
Uri mPeople = android.provider.Contacts.People.CONTENT_URI;
|
|
|
|
Uri mPhone = android.provider.Contacts.Phones.CONTENT_URI;
|
|
|
|
Uri mEmail = android.provider.Contacts.ContactMethods.CONTENT_EMAIL_URI;
|
|
|
|
|
|
|
|
ContactManager(Activity app)
|
2009-10-10 01:23:21 +08:00
|
|
|
{
|
2009-11-03 07:43:09 +08:00
|
|
|
mApp = app;
|
2009-10-10 01:23:21 +08:00
|
|
|
}
|
|
|
|
|
2009-11-03 07:43:09 +08:00
|
|
|
private void getColumnData(Cursor cur){
|
2009-10-10 01:23:21 +08:00
|
|
|
|
2009-11-03 07:43:09 +08:00
|
|
|
ContentResolver cr = mApp.getContentResolver();
|
|
|
|
|
2009-10-01 06:34:28 +08:00
|
|
|
if (cur.moveToFirst()) {
|
|
|
|
|
|
|
|
String name;
|
2009-11-03 07:43:09 +08:00
|
|
|
String email;
|
|
|
|
String phoneNumber;
|
|
|
|
int nameColumn = cur.getColumnIndex(People.NAME);
|
2009-10-01 06:34:28 +08:00
|
|
|
int phoneColumn = cur.getColumnIndex(People.NUMBER);
|
|
|
|
do {
|
|
|
|
// Get the field values
|
2009-11-03 07:43:09 +08:00
|
|
|
name = cur.getString(nameColumn);
|
2009-10-01 06:34:28 +08:00
|
|
|
phoneNumber = cur.getString(phoneColumn);
|
2009-11-03 07:43:09 +08:00
|
|
|
|
2009-10-01 06:34:28 +08:00
|
|
|
} while (cur.moveToNext());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 07:43:09 +08:00
|
|
|
public void findContacts()
|
|
|
|
{
|
|
|
|
|
|
|
|
// Form an array specifying which columns to return.
|
|
|
|
String[] projection = new String[] {
|
|
|
|
People._ID,
|
|
|
|
People.NAME,
|
|
|
|
People.NUMBER
|
|
|
|
};
|
|
|
|
|
|
|
|
// Make the query.
|
|
|
|
Cursor managedCursor = mApp.managedQuery(mPeople,
|
|
|
|
projection, // Which columns to return
|
|
|
|
null, // Which rows to return (all rows)
|
|
|
|
null, // Selection arguments (none)
|
|
|
|
// Put the results in ascending order by name
|
|
|
|
People.DISPLAY_NAME + " ASC");
|
|
|
|
|
|
|
|
this.getColumnData(managedCursor);
|
|
|
|
}
|
|
|
|
|
2009-10-01 06:34:28 +08:00
|
|
|
}
|