androidkotlinpicassoopenweathermap

Not able to load openweatherIcon using Picasso


I am trying to use the openweather API for my app, and when I try to load the icons, I am not able to do so for some reasons.

This is my mainActivity code that I'm trying to implement so that later on I can try it where I really require it.

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val layout = findViewById<ConstraintLayout>(R.id.Rlayout)
        val eTime = currentTimeMillis()
        val format = SimpleDateFormat("HH", Locale.getDefault())
        val time = format.format(eTime).toInt()

        if(time in 6..11) {
            layout.setBackgroundResource(R.drawable.gradientmorning)
        } else if (time in 12..18) {
            layout.setBackgroundResource(R.drawable.gradientnoon)
        } else if (time > 18 || time < 6) {
            layout.setBackgroundResource(R.drawable.gradientnight)
        }

        context = applicationContext
        mRequest = Singleton.getInstance(this)
        progressBar = findViewById(R.id.loader)

        dailyRV.layoutManager = LinearLayoutManager(this)                      // dailyForecastAdapter
        dailyAdapter = DailyInfoAdapter()
        dailyRV.adapter = dailyAdapter

        hourlyRV.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)       //hourlyAdapter
        hourlyAdapter = HourlyInfoAdapter()
        hourlyRV.adapter = hourlyAdapter

        locationVariable = LocationServices.getFusedLocationProviderClient(this)
        getCLocation(context,mRequest)
        progressBar.visibility = View.VISIBLE
        
        Picasso.get().load("http://openweathermap.org/img/wn/04d@2x.png").into(otherImg)
    }

Any reasons as to why the image isn't being displayed at all.


Solution

  • Open weathermap supports https. So it's recommended to use https in url. From android pie , http urls not permitted directly. You have to use https or if https is not supported , you should add cleartexttraffic flag or xml network config for particular domain in AndroidManifest.xml

    Picasso.get().load("https://openweathermap.org/img/wn/04d@2x.png").into(otherImg)