从Firebase检索的图像视图中设置墙纸-Android

时间:2019-03-23 04:08:19

标签: android firebase firebase-realtime-database android-wallpaper wallpapermanager

我是android新手。我想从imagebase设置墙纸,该墙纸是从firebase检索的。我做了一个下载并设置按钮。下载按钮效果很好。设置按钮不起作用。我已经在Stackoverflow上看到了答案,但是它们充满了内置的可绘制墙纸。那么如何在从Firebase检索图像的imageview中设置墙纸

这是代码:

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);



    }
}

0 个答案:

没有答案