EDIT: So apparently the images I'm trying to use are too large. Anyway I can get around this? I'm trying to eventually crop them and set them as my wallpaper programmatically. I've tried a smaller image and it works. Any tips for larger images?
So I'm trying to get an image from a url using Picasso, but when I use the .get() method I'm getting this:
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:601)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:577)
at com.squareup.picasso.BitmapHunter.decodeStream(BitmapHunter.java:142)
at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:217)
at com.squareup.picasso.RequestCreator.get(RequestCreator.java:385)
protected Bitmap doInBackground(String... name) {
try {
return Picasso.with(myContext)
.load("https://i.redd.it/4l2boppcmn1x.jpg")
.get();
} catch (Exception e) {
android.util.Log.e(TAG, "Failed to retrieve submissions", e);
return null;
}
}
Use resize with Picasso
return Picasso.with(myContext)
.load("https://i.redd.it/4l2boppcmn1x.jpg")
.resize(500, 300)
.get();