Is there a way to filter contacts by "organization" in the agenda of Android contacts, when triggered through other activity?

Asked

Viewed 209 times

1

In one app for Android, I intend to open the contacts agenda from another Activity via Intent, but I would like to see only contacts that bring a specific value in the "Organization" field. There is a way to specify this in the Intent that opens the contacts' agenda? It follows the current code, in which the Intent is started at the click of the button getContactDetails:

getContactDetails.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        //Inicia atividade de lista de contatos, para obter os dados do contato
        Intent intent = new Intent(Intent.ACTION_PICK,
                                   ContactsContract.Contacts.CONTENT_URI);
        startActivityForResult(intent, PICK_CONTACT);
    }
});

2 answers

1

Exactly this you can do as is done the operation in any database on android.

String[] projection = new String[]{Calls.NUMBER, Calls.DURATION};
Cursor cur = context.getContentResolver().query(Calls.CONTENT_URI, projection, null, null, Calls.DATE +" desc");

In the example above I am taking in my case the links, as you need the contacts just exchange something like:

Cursor cursor = getContentResolver().query(People.CONTENT_URI, null, null, null, null); 
  • Claudsan, I understand that the query will return me the filtered results, but this will show me only the selected contacts in the default contacts application itself Android? I imagine it takes a Intent for that, no?

0

There is yes ,here is a more detailed example you can sort by any field you want

https://developer.android.com/training/contacts-provider/retrieve-details.html

Below excerpt directly from the documentation cited above.

Defines the Sort order

Sets a Sort order for the returned Cursor. Since you’re retrieving a specific data type, omit the Sort on MIMETYPE. Instead, if the type of Detail data you’re Searching includes a subtype, Sort on it. For example, for email data you can Sort on Email.TYPE:

private static final String SORT_ORDER = Email.TYPE + " ASC ";
  • @clausdan, but this scheme would be to get the data on a list, wouldn’t it? What I want is not purely the filtered data (result of a query), I intend to use the activity of contacts agenda showing only the contacts of a given company, for example, being returned only the contact that the user select (in the case by means of the callback onActivityResult).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.