How to get a Contact object by Android SDK

Hi all,

I’m using android-textile and trying to add a contact,

  • The function returns a mobile.SearchHandle object, and
  • The contacts.add function accepts a io.textile.pb.Model.Contact object.

How can I get a Contact object described in the official doc:

Contact searchResult = // Should be a Contact object as returned by contact search


Hi @bofu, good question. Because of the decentralized and asynchronous nature of searching for contacts on Textile, it’s not as simple as getting a set of results back from a function. This is how you do it:

  1. Create an implementation of TextileEventListener or extend BaseTextileEvenListener and register your event listener using Textile.instance().addEventListener().
  2. Your event listener will receive contact search results in void contactQueryResult(final String queryId, final Contact contact);
  3. When the query is done running, your listener’s void queryDone(final String queryId); method will be called with the query id provided by SearchHandle.getId() on the SearchHandle returned by public SearchHandle ContactQuery query, final QueryOptions options)

I realize this API is a little tricky, but it does work. I’d be open to ideas about how to make it easier to use, such as making the search method accept a lambda parameter that will receive the search result events and a “done” event.

1 Like