Paul Steven
Paul Steven

Reputation: 41

Set a wallpaper from the image view retrieved from firebase - android

I am new to android. I want to set a wallpaper from the imageview which is retrieved from the firebase. I made a download and set button. The download button works great. The set button doesn't work. I have seen answers on Stackoverflow but they are full of built-in drawable wallpapers. so how to set the wallpaper from the imageview where the image is retrieved from the firebase

Here's the Code:

public class ViewWallActivity extends AppCompatActivity {
    CollapsingToolbarLayout collapsingToolbarLayout;
    Button download;
    Button buttonSetWallpaper;
    ImageView i1;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_wall);

        final Target target = new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {

            }

            @Override
            public void onBitmapFailed(Exception e, Drawable errorDrawable) {

            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {

            }
        };

        initialize();

        Picasso.get().load(Utils.selected_wallpaper.getImageLink()).into(i1);


        buttonSetWallpaper.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Picasso.get().load(Utils.selected_wallpaper.getImageLink()).into(target);

            }
        });

        download.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(ContextCompat.checkSelfPermission(ViewWallActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)==PackageManager.PERMISSION_GRANTED)
                {
                    String filename = UUID.randomUUID().toString() + ".png";

                    AlertDialog.Builder b = new AlertDialog.Builder(ViewWallActivity.this);
                    b.setMessage("Downloading....");
                    AlertDialog alertDialog =b.create();
                    alertDialog.show();

                    Picasso.get().load(Utils.selected_wallpaper.getImageLink()).into(new SaveImageHelper(getBaseContext(),alertDialog,getApplicationContext().getContentResolver(),filename,"Mini Image"));


                }
                else
                    ActivityCompat.requestPermissions(ViewWallActivity.this,  new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},9);



            }
        });
    }
    private void initialize()
    {
        i1 = (ImageView)findViewById(R.id.thumbImage);

        collapsingToolbarLayout = (CollapsingToolbarLayout)findViewById(R.id.collapsingToolbarLayout);
        //fabDownload = (FloatingActionButton)findViewById(R.id.fab_download);
        download = (Button)findViewById(R.id.btn) ;
        buttonSetWallpaper = (Button)findViewById(R.id.wallbtn);
        //fabWallpaper = (FloatingActionButton)findViewById(R.id.fab_wallpaper);

        collapsingToolbarLayout.setTitle(Utils.CATEGORY_SELECTED);



    }
}

Upvotes: 0

Views: 192

Answers (0)

Related Questions