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

问题描述 投票:0回答:1

我有图像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)
    }
android android-file android-fileprovider
1个回答
0
投票
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!"));

}
© www.soinside.com 2019 - 2024. All rights reserved.