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/[email protected]").into(otherImg)
}
Any reasons as to why the image isn't being displayed at all.
CodePudding user response:
I am using Glide and I add a callback to see what is the exception
the stacktrace print Caused by: java.io.IOException: Cleartext HTTP traffic to openweathermap.org not permitted
. So I added android:usesCleartextTraffic="true"
to application in AndroidManifest and it works now.
CodePudding user response:
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/[email protected]").into(otherImg)
CodePudding user response:
Try adding size for an image you are trying to display. Like this :
Picasso.get()
.load("http://openweathermap.org/img/wn/[email protected]")
.resize(255,255)
.centerCrop()
.into(otherImg);