I am successfully retrieving the Image and displaying it in a list but while i am sharing it, it's showing that "Empty file can not be attched"
here are what I've tried
holder.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String PATH = "/mnt/sdcard/"+ listItem.getImg();
File f = new File(PATH);
Uri yourUri = Uri.fromFile(f);
// Uri contenturi= FileProvider.getUriForFile(context," com.astu360.bjp2017",f);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("Image/*");
intent.putExtra(Intent.EXTRA_STREAM, yourUri);
intent.putExtra(Intent.EXTRA_TEXT,"These are the content..");
context.startActivity(Intent.createChooser(intent,"Share via.."));
}
});
Any help and suggestion will be appreciated.
you should use bitmap to compress and try chooser.
Bitmap icon = mBitmap;
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 150, bytes);
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "file.jpg");
try {
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
fos.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/file.jpg"));
startActivity(Intent.createChooser(share, "Share..."));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.