我有图像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!"));
}