0

I am developing a Weather app ,in that trying to build Uri that looks like Content://com.example.weather.app/Location/locationName?Date=12012017

The documentation says Uri reference has pattern as ://?#

trying to understand this following code

 public static Uri buildWeatherLocation(String locationSetting) {
                    return CONTENT_URI.buildUpon().appendPath(locationSetting).build();
                }

                public static Uri buildWeatherLocationWithStartDate(
                        String locationSetting, long startDate) {
                    long normalizedDate = normalizeDate(startDate);
                    return CONTENT_URI.buildUpon().appendPath(locationSetting)
                         .appendQueryParameter(COLUMN_DATE,Long.toString(normalizedDate)).build();     

                }

what is the actual difference and when we use appendPath() and appendQueryParameter() methods? why can't we use appendQueryParameter() for locationSetting ,bit confusing suggestions plz

beeb
  • 1,615
  • 1
  • 12
  • 24
Smitha_nj
  • 87
  • 3
  • 12

2 Answers2

1

appendPath() is for path segments and appendQueryParameter() for query params with key value (in your example Date=12012017).

Check this link for more info and examples: Use URI builder in Android or create URL with variables

Community
  • 1
  • 1
beeb
  • 1,615
  • 1
  • 12
  • 24
0

appendQueryParameter is for query string parameters and appendPath is for site path

Django
  • 222
  • 1
  • 5
  • can .appendPath(locationSetting) be used as .appendQueryParameter(LOCATIONNAME,locationSetting) so that it becomes part of – Smitha_nj Jan 12 '17 at 08:59