Java Code Examples for android.provider.Contacts.People#CONTENT_URI

The following examples show how to use android.provider.Contacts.People#CONTENT_URI . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoaderRetainedSupport.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    // This is called when a new Loader needs to be created.  This
    // sample only has one Loader, so we don't care about the ID.
    // First, pick the base URI to use depending on whether we are
    // currently filtering.
    Uri baseUri;
    if (mCurFilter != null) {
        baseUri = Uri.withAppendedPath(People.CONTENT_FILTER_URI, Uri.encode(mCurFilter));
    } else {
        baseUri = People.CONTENT_URI;
    }

    // Now create and return a CursorLoader that will take care of
    // creating a Cursor for the data being displayed.
    String select = "((" + People.DISPLAY_NAME + " NOTNULL) AND ("
            + People.DISPLAY_NAME + " != '' ))";
    return new CursorLoader(getActivity(), baseUri,
            CONTACTS_SUMMARY_PROJECTION, select, null,
            People.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
}
 
Example 2
Source File: LoaderCursorSupport.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    // This is called when a new Loader needs to be created.  This
    // sample only has one Loader, so we don't care about the ID.
    // First, pick the base URI to use depending on whether we are
    // currently filtering.
    Uri baseUri;
    if (mCurFilter != null) {
        baseUri = Uri.withAppendedPath(People.CONTENT_FILTER_URI, Uri.encode(mCurFilter));
    } else {
        baseUri = People.CONTENT_URI;
    }

    // Now create and return a CursorLoader that will take care of
    // creating a Cursor for the data being displayed.
    String select = "((" + People.DISPLAY_NAME + " NOTNULL) AND ("
            + People.DISPLAY_NAME + " != '' ))";
    return new CursorLoader(getActivity(), baseUri,
            CONTACTS_SUMMARY_PROJECTION, select, null,
            People.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
}
 
Example 3
Source File: PhoneNumberViewItem.java    From LibreTasks with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public View buildUI(DataType initData) {
  if (initData != null) {
    editText.setText(initData.getValue());
  }
  
  ContentResolver cr = activity.getContentResolver();
  List<String> contacts = new ArrayList<String>();
  // Form an array specifying which columns to return.
  String[] projection = new String[] {People.NAME, People.NUMBER };
  // Get the base URI for the People table in the Contacts content provider.
  Uri contactsUri = People.CONTENT_URI;
  // Make the query.
  Cursor cursor = cr.query(contactsUri, 
      projection, // Which columns to return
      null, // Which rows to return (all rows)
      null, // Selection arguments (none)
      Contacts.People.DEFAULT_SORT_ORDER);
  if (cursor.moveToFirst()) {
    String name;
    String phoneNumber;
    int nameColumn = cursor.getColumnIndex(People.NAME);
    int phoneColumn = cursor.getColumnIndex(People.NUMBER);
    do {
      // Get the field values of contacts
      name = cursor.getString(nameColumn);
      phoneNumber = cursor.getString(phoneColumn);
      contacts.add(name + ": " + phoneNumber);
    } while (cursor.moveToNext());
  }
  cursor.close();
  
  String[] contactsStr = new String[]{};
  ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity,
      android.R.layout.simple_dropdown_item_1line, contacts.toArray(contactsStr));
  
  editText.setAdapter(adapter);
  editText.setThreshold(1);
  return(editText);
}