Android Programming Tutorials

(Romina) #1
Seeking the Proper Level

public String getDisplayNameField() {
return(Contacts.DISPLAY_NAME);
}
}

We simply generate and return the Cursor using the same query as before,


and indicate that Contacts.DISPLAY_NAME is what should be used from the


Cursor for the dialog.


Step #3: Implement the Interface: the Old Way..............................


We also need an implementation of this interface that used the old


Contacts content provider, as opposed to the new ContactsContract


content provider. The good news is that while the classes changed, the


general concepts are still the same. It is still a content provider, which we


can query against to get the data we need. All we need is the proper content


Uri, the proper set of projection columns, the right WHERE clause, and so


on.


With that in mind, add the following as


LunchList/src/apt/tutorial/OldMobileContacts.java:


package apt.tutorial;

import android.app.Activity;
import android.database.Cursor;
import android.provider.Contacts;

class OldMobileContacts implements MobileContactsBridge {
public Cursor getMobileNumbers(Activity host) {
String[] PROJECTION=new String[] { Contacts.Phones._ID,
Contacts.Phones.NAME,
Contacts.Phones.NUMBER
};
String[] ARGS={String.valueOf(Contacts.Phones.TYPE_MOBILE)};

return(host.managedQuery(Contacts.Phones.CONTENT_URI,
PROJECTION,
Contacts.Phones.TYPE+"=?", ARGS,
Contacts.Phones.NAME));
}

public String getDisplayNameField() {
return(Contacts.Phones.NAME);

373
Free download pdf