Seeking the Proper Level
- A Cursor containing the contact's ID, name, and mobile phone
number - The name of the field that is the contact's name, so we can supply
this to the AlertDialog.Builder, so it knows how to display the list
With that in mind, let us define a Java interface, for which we will create
implementations using the old and new contacts API. Add the following as
LunchList/src/apt/tutorial/MobileContactsBridge.java:
package apt.tutorial;
import android.app.Activity;
import android.database.Cursor;
interface MobileContactsBridge {
Cursor getMobileNumbers(Activity host);
String getDisplayNameField();
}
Step #2: Implement the Interface: the New Way.............................
The existing code we added to DetailForm in the previous tutorial can be
largely copied-and-pasted into a NewMobileContacts class that implements
this interface. Add the following as
LunchList/src/apt/tutorial/NewMobileContacts.java:
package apt.tutorial;
import android.app.Activity;
import android.database.Cursor;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.CommonDataKinds.Phone;
class NewMobileContacts implements MobileContactsBridge {
public Cursor getMobileNumbers(Activity host) {
String[] PROJECTION=new String[] { Contacts._ID,
Contacts.DISPLAY_NAME,
Phone.NUMBER
};
String[] ARGS={String.valueOf(Phone.TYPE_MOBILE)};
return(host.managedQuery(Phone.CONTENT_URI,
PROJECTION, Phone.TYPE+"=?",
ARGS, Contacts.DISPLAY_NAME));
}