简体   繁体   English

通过Android中的其他应用共享图像

[英]Share image via other apps in android

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..."));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM