0

I have this adapter class. What I want to achieve is I have several images as .png in assets folder and I have displayed them in cardview with a button on click of which that particular image should get downloaded to phone's memory. I tried from a lot of suggestions on the net but they didn't help. can anyone please solve my this problem??
The ImageListingDao here mentioned is the dao class with getter and setter of id and imagepath. I have db In the asset folder through which I am loading images in the cards.

public class ImageListingAdapter extends RecyclerView.Adapter<ImageListingAdapter.ViewHolder> {

    private ArrayList<ImageListingDao> imageslist;
    private Context imagelist_context;


    public ImageListingAdapter(Context context, ArrayList<ImageListingDao > imageslist){
        this.imageslist= imageslist;
        imagelist_context= context;
    }


    @NonNull
    @Override
    public ImageListingAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.image_display_binder, parent, false);
        return new ImageListingAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final ImageListingAdapter.ViewHolder holder, final int position) {

        try
        {
            AssetManager assetManager = imagelist_context.getAssets();

            InputStream is = assetManager.open(""+imageslist.get(position).getImageListingpath());
            Bitmap bitmap = BitmapFactory.decodeStream(is);
            holder.image_listing.setImageBitmap(bitmap);
            is .close();
        }
        catch(IOException ex)
        {
            ex.printStackTrace();
        }
        catch (Exception e){
            e.printStackTrace();
        }

        holder.idownload.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // what should I write here!!??    
            }
        });

    }

    @Override
    public int getItemCount() {
        return imageslist.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        // TextView textmessage_text_name;
        ImageView image_listing;
        ImageButton idownload, ishare, ifav;

        public ViewHolder(View itemView) {
            super(itemView);
            image_listing = itemView.findViewById(R.id.image_detail_view);
            idownload= itemView.findViewById(R.id.image_detail_download);
            ishare= itemView.findViewById(R.id.image_detail_share);
            ifav= itemView.findViewById(R.id.image_detail_fav);    
        }
    }    
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

You take the bitmap and save it like any other image you take with the camera.

You already have the Bitmap, so here‘s the link to store the image.

android - save image into gallery

Dominik 105
  • 74
  • 1
  • 8
  • So 2 part of the question. 1. were you able to get the correct bitmap. 2. if you have the correct bitmap, what error/exception are you seeing while saving it. – Amit K. Saha Jan 11 '19 at 19:35