我正在按照本教程使用 FileProvider 而不是Uri.FromFile()但是我不確定如何在我的服務中使用 FileProvider。FileProvider.getUriForFile()需要第一個參數的上下文,但因為我在我的服務中使用它,所以我沒有活動上下文。我應該做些什么?我需要改變這個:Uri swatchImageUri = Uri.fromFile(favoritesImageFile);對于他們上面的建議。這是我在不使用 FileProvider 的情況下遇到的當前異常:2019-07-23 23:04:42.748 11034-11034/com.company.projname E/AndroidRuntime: FATAL EXCEPTION: main Process: com.company.projname, PID: 11034 android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.company.projname/cache/colors.png exposed beyond app through ClipData.Item.getUri() at android.os.StrictMode.onFileUriExposed(StrictMode.java:1978) at android.net.Uri.checkFileUriExposed(Uri.java:2371) at android.content.ClipData.prepareToLeaveProcess(ClipData.java:963) at android.content.Intent.prepareToLeaveProcess(Intent.java:10216) at android.content.Intent.prepareToLeaveProcess(Intent.java:10222) at android.content.Intent.prepareToLeaveProcess(Intent.java:10201) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1667) at android.app.Activity.startActivityForResult(Activity.java:4586)
android.os.FileUriExposedException: 在 android.os.
慕桂英4014372
2023-04-19 16:48:16