Search code examples
androidcrashapkandroid-fileandroid-fileprovider

Android App is crashing because of android.os.FileUriExposedException


The app is crashing when I'm trying update app. In our app we are saving the updated version on cache and then try to install the app from cache. App is crashing because of android.os.FileUriExposedException I found the log android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData() I know the solution of this problem. I fixed in the newer version of the app. For new version of app, I used FileProvider for apk installation, but old version of app use Uri.fromFile(dest). Now the problem is the auto update of the app. I need to update app automatically from the old version of the app. When I tried to update new app it download the app, but when try to install app it is crashing. Is there any way to install app from the old version of app? NB: previous developer didn’t use play store for our app.

Thanks in advance


Solution

  • don't use Uri.fromFile() you are using fileprovider so use FileProvider.getUriForFile(Context context, String authority, File file) otherwise what is the use of file provider.

    FileProvider doc -> https://developer.android.com/reference/androidx/core/content/FileProvider