簡體   English   中英

通過Android中的其他應用共享圖像

[英]Share image via other apps in android

我已經成功檢索了圖像並將其顯示在列表中,但是當我共享它時,它顯示“無法附加空文件”

這是我嘗試過的

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

任何幫助和建議,將不勝感激。

您應該使用位圖壓縮並嘗試選擇器。

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