[英]Why Uri.fromFile() will not work on Android 7.0+, with a targetSdkVersion of 24 or higher. and what can be the alternate solution ? (Kotlin)
[英]Why there is no problem with Uri.fromFile even in android:targetSdkVersion = “25”?
在 Android 應用程序中,
我聽說我不應該將Uri.fromFile
用於targetSdkVersion >= 24
如下鏈接:
但是我在以下條件下使用它沒有任何崩潰:
android:targetSdkVersion = "25" , 安卓牛軋糖
else if (requestCode > Constants.Uri_M4_Images_Camera_Filter)
{
if (resultCode == RESULT_OK)
{
Bitmap photo = (Bitmap) data.getExtras().get("data");
Uri_M4_ViewPager_M4Image_Camera = Uri.fromFile(saveImage2(photo));
我可以在 Picasso 中使用Uri_M4_ViewPager_M4Image_Camera
沒有問題,為什么?
Uri.fromFile()
的問題在於將Uri
傳遞給Intent
另一個應用程序。 這將觸發FileUriExposedException
。 即使您繞過它,在 Android 10+ 上,其他應用程序也無法訪問該文件。
在您自己的應用程序中使用Uri.fromFile()
通常是不必要的。 例如,畢加索可以使用File
; 您無需將一個轉換為Uri
即可讓畢加索將其轉換回來。 但是,如果您真的想在自己的應用程序中使用file
Uri
,歡迎您這樣做。 只是不要將它傳遞給另一個應用程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.