【发布时间】:2018-11-08 08:23:52
【问题描述】:
我在这里分享图像意图。图像位于可绘制文件夹中。
给这个excpetion.
android.os.FileUriExposedException:
file:///storage/emulated/0/Android/data/com.example.arkkhano.myapplication/cache/myImage.png exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1958)
at android.net.Uri.checkFileUriExposed(Uri.java:2356)
代码:
sharing_img.setOnClickListener {
val myDrawable = tv_view_home2e.drawable
val bitmap = (myDrawable as BitmapDrawable).bitmap
val file = File(externalCacheDir,"myImage.png")
val fOut = FileOutputStream(file)
bitmap.compress(Bitmap.CompressFormat.PNG,90,fOut)
fOut.flush()
fOut.close()
file.setReadable(true,false)
val intent = Intent(Intent.ACTION_SEND)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(file))
intent.type = "image/png"
intent.putExtra(Intent.EXTRA_SUBJECT,"Subject here")
startActivity(Intent.createChooser(intent,"Share to "))
}
【问题讨论】:
-
检查这个关于文件提供者的答案:stackoverflow.com/a/50503528/1574250
-
看起来您搜索答案的时间不超过 3 秒。