java - 如何将参数从主 Activity 传递到@Get API

标签 java android retrofit2

public interface CurrentWeatherApi {
    @GET("/data/2.5/weather?q=California&APPID=e8b8a84d0dcbec867ba66a34d376562f")
    Call<CurrentWeather> getCurrentWeather();
}

这是我的界面,我想从动态获取 API 的主 Activity 中传递城市名称

最佳答案

进行以下更改并从传递这些参数的 Activity 中调用

   public interface CurrentWeatherApi {

    @GET("/data/2.5/weather")
    Call<CurrentWeather> getCurrentWeather(@Query("q") String cityName,@Query("APPID") String appID);

}

因此调用如下所示

Call<CurrentWeather> repos = service.getCurrentWeather("California","e8b8a84d0dcbec867ba66a34d376562f");

关于java - 如何将参数从主 Activity 传递到@Get API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48154888/

相关文章:

JAVA - WELD 装饰器错误

用于预览和 MediaCodec 输入 Surface 的 Android Camera2 管道

android - 验证视频 View appium (java) android

java - 将一个列表中的项目添加到java中的另一个列表中

android - 使用 Retrofit 获取数据并插入到 SQLite 数据库

安卓分页 : Using APIs with Retrofit and Gson (Crash)

java - 在带有 SonarQube 的 Java 中,如何修复 `Only the sign of the result should be examined`

java - 为什么会出现不同的异常?

android - kotlin.coroutines.intrinsics.CoroutineSingletons 不能转换为 retrofit2.Response

java - 将 Android 的字符串资源与硬编码字符串连接起来