我成功检索图像并将其显示在列表中,但在我分享时,它显示“无法附加空文件”
这是我试过的
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.."));
}
});
任何帮助和建议都将不胜感激。
答案 0 :(得分:0)
你应该使用位图压缩并尝试选择器。
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..."));