簡體   English   中英

Android - 如何使用 URI 共享圖像?

[英]Android - How to Share image using URI?

我有圖像 uri,我正在嘗試使用下面的代碼共享它,但它不起作用。

共享意圖已打開,但那里沒有圖像。 請在這件事上給予我幫助

private fun ivShareClickListener(position: Int) {
        var file = File(dataList[position].uri.path)
        val sharingIntent = Intent(Intent.ACTION_SEND)
        //sharingIntent.type = "*/*"
        val apkURI = FileProvider.getUriForFile(
            context, context.applicationContext.packageName + ".provider", file
        )
        sharingIntent.setDataAndType(apkURI, "*/*")
        sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
        startActivity(context, Intent.createChooser(sharingIntent, "Share image using"), null)
    }
private void shareImage() {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
String imagePath = Environment.getExternalStorageDirectory() + "/myImage.png";
File imageFileToShare = new File(imagePath);
Uri uri = Uri.fromFile(imageFileToShare);
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Image!"));

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM