【问题标题】:Uri-Difference between appendPath() and appendQueryParameter()appendPath() 和 appendQueryParameter() 之间的 Uri-Difference
【发布时间】:2017-05-27 06:45:49
【问题描述】:

我正在开发一个天气应用程序,试图构建一个看起来像 内容://com.example.weather.app/Location/locationName?Date=12012017

文档说 Uri 引用的模式为 ://?#

试图理解以下代码

 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();     

                }

实际区别是什么?我们何时使用appendPath()appendQueryParameter() 方法? 为什么我们不能使用appendQueryParameter() 进行位置设置,有点令人困惑的建议plz

【问题讨论】:

    标签: android


    【解决方案1】:

    appendPath() 用于路径段,appendQueryParameter() 用于具有键值的查询参数(在您的示例中 Date=12012017)。

    查看此链接以获取更多信息和示例: Use URI builder in Android or create URL with variables

    【讨论】:

      【解决方案2】:

      appendQueryParameter 用于查询字符串参数,appendPath 用于站点路径

      【讨论】:

      • 可以将 .appendPath(locationSetting) 用作 .appendQueryParameter(LOCATIONNAME,locationSetting) 使其成为 的一部分
      猜你喜欢
      • 1970-01-01
      • 2015-05-10
      • 1970-01-01
      • 2011-05-10
      • 2023-03-08
      • 1970-01-01
      • 2020-10-22
      • 1970-01-01
      相关资源
      最近更新 更多