天气细节无法在Android 9 Pie中使用

时间:2019-11-13 13:43:36

标签: android-studio openweathermap yahoo-weather-api

天气可在除Android 9之外的所有Android版本上运行

我已经在所有android版本上测试了其在android 9以外的所有os版本上的正常工作。即使没有错误或异常也正在产生。这里有人知道发生了什么吗? 代码

            //weather list
            weathers = new ArrayList<>();
            LocationInfo locationInfo = ConfigPreferences.getLocationConfig(getActivity());
            OkHttpClient client = new OkHttpClient();
            Request request = new Request.Builder().url(URL + "lat=" + locationInfo.latitude + "&lon=" + locationInfo.longitude + "&lang=" + Locale.getDefault().getLanguage() + API_ID).build();

            Log.i("URL_WITHER", URL + "lat=" + locationInfo.latitude + "&lon=" + locationInfo.longitude + "&lang=" + Locale.getDefault().getLanguage() + API_ID);
            //receive json and parse
            Response response = client.newCall(request).execute();
            String jsonData = response.body().string();
            if (jsonData != null) {
                JSONObject Jobject = new JSONObject(jsonData);
                JSONArray Jarray = Jobject.getJSONArray("list");
                for (int i = 0; i < Jarray.length(); i++) {
                    JSONObject object = Jarray.getJSONObject(i);
                    JSONObject main = object.getJSONObject("main");
                    JSONArray weather = object.getJSONArray("weather");
                    String desc = weather.getJSONObject(0).getString("description");
                    Log.i("URL_WITHER", "desc : " + desc);
                    String icon = weather.getJSONObject(0).getString("icon");
                    String date = object.getString("dt_txt");
                    String temp = main.getString("temp");
                    String temp_min = main.getString("temp_min");
                    String temp_max = main.getString("temp_max");
                    String humidity = main.getString("humidity");
                    JSONObject wind = object.getJSONObject("wind");
                    String windSpeed = wind.getString("speed");

                    //convert weather degree and add to weather list
                    weathers.add(new sjtechnologies.muslimapp.model.Weather
                            (date, Math.round(Float.valueOf(temp) - 272.15f) + "",
                                    Math.round(Float.valueOf(temp_min) - 272.15f) + "",
                                    Math.round(Float.valueOf(temp_max) - 272.15f) + "",
                                    icon, desc, humidity, windSpeed));
                }


            }
        }```

0 个答案:

没有答案