I fixed the issue by changing the saved string url to one with out backslashes
String thumburl = (videoJsonObj.getString("thumbnail_url"));
thumburl = thumburl.replace("\'", "");
This now works across all my AVD API levels. I still want to know why Picasso corrected this by default on API 25, but not API 27 or 28. What is the difference in the way those Android versions and Picasso work together to load URL resources?
UPDATE: I spoke too soon... it appears to still not be working on the new Android version (Pie) on the AS emulator. After some digging and lots of logging I realized that a couple of things were happening:
First, the JSONObject.getString()
method seems to automatically remove the "\" when it retrieves the url value from the JSON using the key. As logging the value after this extraction shows the url without backticks, even without the above code. (Still nice to have it just in case that doesn't happen automatically by the system.)
Thus the real problem was in Android Pie's new feature blocking all http traffic by default. You can bypass this feature in your app as shown here
OR you can do a bunch of string manipulation to keep your app's network calls more secure by default assuming the site you are accessing has https
addresses, but for some reason returns http
results by default in their JSON responses, like in my case.
I chose to keep it to https as that is the future by adding the 's' if it wasn't present in my results with the below string manipulation:
String thumburl = (videoJsonObj.getString("thumbnail_url"));
thumburl = thumburl.replace("\'", "");
StringBuilder imageUrlStringBuilder = new StringBuilder(thumburl);
if(imageUrlStringBuilder.charAt(4) != 's') {
imageUrlStringBuilder.insert(4, 's');
}
thumburl = imageUrlStringBuilder.toString();
video.setVideoThumbnailUrl(thumburl);
I believe this string manipulation is the better way to go as it won't break if the API updates to return https
instead of it's current return of http
addresses because it checks for the 's' character at the right place; however, it will also force load https
version (as this is the future trend of web) and this might not work with outdated sites/data sources. (This worked for me because in my case this site. https://s1.dmcdn.net/p0i-5.jpg
and http://s1.dmcdn.net/p0i-5.jpg
both return the same result.)