Passing parameters via URI in Android

Is it possible (or recommended) to pass parameters to content providers via URIs on Android, similar to how web addresses use them? That is, can I use name / value pairs in the content: // URIs?

For example, I have a search provider that can search by name. I pass it the URI as follows:

Content: //com.example.app/name/john

This will return anyone with "john" in their names, including John, Johnathon, Johnson, etc.

I want to have an option (but not a requirement) for searching with exact names and not finding partial matches. I was thinking of doing something like this:

Content: //com.example.app/name/john Exact = True

This will mean that the search provider returns only those names that exactly match "John". But I have not seen any other examples of such parameters that are used in Android. Is there a better way? What am I missing here?

Thanks!

+6
android
source share
2 answers

if you want to pass query parameters, you can use the appendQueryParameter () method when creating your URI

LoaderFactory.createCursorLoader(this, MyProvider.MY_CONTENT_URI.buildUpon().appendQueryParameter( MyProvider.MY_PARAM_NAME, myParamValue).build(), projection, null, null, null); 

And then access the parameter value using getQueryParameter ()

 String paramValue = uri.getQueryParameter(MyProvider.MY_PARAM_NAME); 
+12
source share

No, as far as I saw, any parameters are removed from the URLs of the content provider (although I don’t know why), I worked on this, adding parameters using "/" and a specific prefix and parsing them manually, something like this:

 content://com.example.app/name/john/paramexact/true 
+1
source share

All Articles