Home > Articles > Home & Office Computing > Entertainment/Gaming/Gadgets

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Narrowing the Data Returned by a Query

Following the RFC standard, we can use specific URIs to narrow down the data we are querying for. In our application, we might want to select a walk depending on its creation date. A URI of the following form, would be used (the from and to fields are in "zero epoch" value):

content://com.informit.mywalks.Walks/walks?from=1174497980534&to=1174497980536

To enable such a query, we will set the where clause in the query method of the instantiated content provider, as follows:

String from = uri.getQueryParameter("from"); 
tring to = uri.getQueryParameter("to"); 
if (from != null) { 
    qb.appendWhere("created>" + from); 
} 
if (to != null) { 
    // There seems to be a bug here. We need to manually ensure the AND 
    // is part of the where clause 
    qb.appendWhere(" AND created<" + to);
}

The code is straightforward, and you can extend it to any key/value pair. You can build up more complicated URIs in order to access the data in different ways.

  • + Share This
  • 🔖 Save To Your Account