我正在尝试在 recycleview android 中从 cardview 共享和保存 imageview。我的 imagview 是一个静态文件,我想将此文件保存在 android 库中,并在单击共享图像按钮时共享此图像。请看下面的快照!
我的代码在下面!
public class PicCardViewHolder extends RecyclerView.ViewHolder {
public TextView pic_name;
public ImageView st_image;
public ImageView save_img;
public ImageView share_st_img;
public Drawable drawable;
public Bitmap bitmap;
public String ImagePath;
public Uri URI;
public Context context;
public PicCardViewHolder(View v) {
super(v);
context = itemView.getContext();
pic_name = (TextView) itemView.findViewById(R.id.pic_name);
st_image = (ImageView) itemView.findViewById(R.id.st_pic);
save_img = (ImageView) itemView.findViewById(R.id.down_img);
share_st_img = (ImageView) itemView.findViewById(R.id.share_pic_st);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = getAdapterPosition();
if (pos == 0) {
//code for save image into gallery android
st_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
drawable = ContextCompat.getDrawable(context, R.drawable.test_image);
bitmap = ((BitmapDrawable) drawable).getBitmap();
ImagePath = MediaStore.Images.Media.insertImage(
context.getContentResolver(),
bitmap,
"demo_image",
"demo_image"
);
URI = Uri.parse(ImagePath);
Toast.makeText(context, "Image Saved Successfully", Toast.LENGTH_LONG).show();
}
});
}
}
});
}
}