0

I need to set an image as wallpaper using RecyclerView. In my adapter i'm using this code:

@Override
    public void onBindViewHolder(ViewHolder viewHolder, final int i) {
        final GridItem nature = mItems.get(i);
        viewHolder.tvspecies.setText(nature.getName());
        viewHolder.imgThumbnail.setImageResource(nature.getThumbnail());

        viewHolder.imgThumbnail.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Log.i("CLick",nature.toString());
                try {
                    wallpaper.setResource(mItems.get(i));
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
    }

so onClick i should set the image as wallpaper but under "setResource" word i have this error:

The method setResource(int) in the type WallpaperManager is not applicable for the arguments (GridItem)

How can i set the item selected from the adapter as wallpaper?

Atlas91
  • 5,754
  • 17
  • 69
  • 141

1 Answers1

0

The reason your program is not working, the method setResource(int) takes in int type as a parameter and not GridItemtype.

Reading more from the documentation

Change the current system wallpaper to the bitmap in the given resource. The resource is opened as a raw data stream and copied into the wallpaper; it must be a valid PNG or JPEG image.

also make sure your app have permission to set wallpaper in manifest

This method requires the caller to hold the permission SET_WALLPAPER.

Kushal Sharma
  • 5,978
  • 5
  • 25
  • 41