0

I'm trying to set wallpaper by downloading an image from internet but it's showing that "get()method" is not found. My Code: In this code wall_set is a button's name

wall_set.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bitmap result=Glide.with(getApplicationContext())
                            .load("http://www.sport-stickers.com/images/2013/CARTOON%20IRON%20ONS/Doraemon/Doraemon%20Iron%20ons%20(Wall%20Stickers)%20N3715.jpg").get();


                    WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
                    try {
                        wallpaperManager.setBitmap(result);
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }
            }
    );
Srinivas Nahak
  • 1,846
  • 4
  • 20
  • 45
  • 1
    Check out the [documentation for Glide](https://github.com/bumptech/glide/wiki). Looks like you should be using `into()` not `get()`. – rundavidrun Jun 18 '17 at 20:22
  • It look like you are missing to add asBitmap() see this answer https://stackoverflow.com/a/27394484/7134908 – Ajeet Choudhary Jun 18 '17 at 20:45

2 Answers2

1

change this part of your code:

Bitmap result=Glide.with(getApplicationContext())
                        .load("http://www.sport-stickers.com/images/2013/CARTOON%20IRON%20ONS/Doraemon/Doraemon%20Iron%20ons%20(Wall%20Stickers)%20N3715.jpg").asBitmap().get();

add "asBitmap"

you might need to add  
asBitmap().into(20, 20). // Width and height

in the following

Meikiem
  • 1,876
  • 2
  • 11
  • 19
0

If you follow Glide sample usage it comes up with that get() method belongs to java.util.concurrent.Future object. And Future class definition is given by the official doc as below.

public interface Future<V> A Future represents the result of an asynchronous computation. Methods are provided to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation. The result can only be retrieved using method get when the computation has completed, blocking if necessary until it is ready. Cancellation is performed by the cancel method. Additional methods are provided to determine if the task completed normally or was cancelled. Once a computation has completed, the computation cannot be cancelled. If you would like to use a Future for the sake of cancellability but not provide a usable result, you can declare types of the form Future and return null as a result of the underlying task.

Sample Usage (Note that the following classes are all made-up.)

interface ArchiveSearcher { String search(String target); }
 class App {
   ExecutorService executor = ...
   ArchiveSearcher searcher = ...
   void showSearch(final String target)
       throws InterruptedException {
     Future<String> future
       = executor.submit(new Callable<String>() {
         public String call() {
             return searcher.search(target);
         }});
     displayOtherThings(); // do other things while searching
     try {
       displayText(future.get()); // use future
     } catch (ExecutionException ex) { cleanup(); return; }
   }
 }

Lets see what happens step by step:

Bitmap theBitmap = Glide. 
        with(this). //in Glide class and returns RequestManager
        load(image_url). // in RequestManager and returns RequestBuilder<Drawable>
        asBitmap(). //in RequestBuilder and returns RequestBuilder<Bitmap>
        submit(). // in RequestBuilder and returns FutureTarget<TranscodeType> which extends Future<>
        get(); // this belongs to Future object which is the result of async computation

public static RequestManager with(Context context) {
    return getRetriever(context).get(context);
  }

public RequestBuilder<Drawable> load(@Nullable Object model) {
    return asDrawable().load(model);
  }


  public RequestBuilder<Bitmap> asBitmap() {
    return as(Bitmap.class).transition(new GenericTransitionOptions<Bitmap>())
            .apply(DECODE_TYPE_BITMAP);
  }

public FutureTarget<TranscodeType> submit() {
    return submit(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL);
  }


public interface FutureTarget<R> extends Future<R>, Target<R> {
}

But more proper and secure solution is by using callback

Glide
    .with(this)
    .load(image_url)
    .asBitmap()
    .into(new SimpleTarget<Bitmap>(100,100) {
        @Override
        public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
            //resource is the resulting bitmap
        }
    });
ugur
  • 3,604
  • 3
  • 26
  • 57