Download and Save Images Using Picasso

前端 未结 3 724
轻奢々
轻奢々 2021-02-05 11:36

I\'m trying to show my news in a custom ListView. Each news is included of some images and I want to

3条回答
  •  野性不改
    2021-02-05 12:25

    Custom target for storing photo in phone gallery.

    public class TargetPhoneGallery implements Target
    {
        private final WeakReference resolver;
        private final String name;
        private final String desc;
    
        public TargetPhoneGallery(ContentResolver r, String name, String desc)
        {
            this.resolver = new WeakReference(r);
            this.name = name;
            this.desc = desc;
        }
    
        @Override
        public void onPrepareLoad (Drawable arg0)
        {
        }
    
        @Override
        public void onBitmapLoaded (Bitmap bitmap, LoadedFrom arg1)
        {
            ContentResolver r = resolver.get();
            if (r != null)
            {
                MediaStore.Images.Media.insertImage(r, bitmap, name, desc);
            }
        }
    
        @Override
        public void onBitmapFailed (Drawable arg0)
        {
        }
    }
    
    Picasso.with(context).load(image[position]).into(new TargetPhoneGallery(view.getContentResolver(), "image name", "image desc"));
    

提交回复
热议问题