0

I am writing an app updater program for my app. After that I make sure that I have my own old apk on the device,the updater worked very well till the MARSH MALLOW and when the NOUGAT version updates, it shows the error, this is what I do from within the app I'm trying to update:

       try {

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    Uri apkURI = FileProvider.getUriForFile(getApplicationContext(),
                            getApplicationContext().getPackageName() + ".provider", new File(filepath));
                    intent.setDataAndType(apkURI, "application/vnd.android.package-archive");
                    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setDataAndType(Uri.fromFile(new File(filepath)),
                            "application/vnd.android.package-archive");
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

The application crashes when trying to open a new existing apk.

this is error log:

android.os.FileUriExposedException: file:///storage/emulated/0/.fTouch_app/Ftouch.jpg exposed beyond app through Intent.getData()

appreciate for help.Thank you.

Nathani Software
  • 111
  • 1
  • 1
  • 7

1 Answers1

0

This looks like your problem.

From the documentation for FileUriExposedException

The exception that is thrown when an application exposes a file:// Uri to another app.

This exposure is discouraged since the receiving app may not have access to the shared path. For example, the receiving app may not have requested the READ_EXTERNAL_STORAGE runtime permission, or the platform may be sharing the Uri across user profile boundaries.

Instead, apps should use content:// Uris so the platform can extend temporary permission for the receiving app to access the resource.

This is only thrown for applications targeting N or higher. Applications targeting earlier SDK versions are allowed to share file:// Uri, but it's strongly discouraged.

Community
  • 1
  • 1
Cheticamp
  • 61,413
  • 10
  • 78
  • 131
  • @NathaniSoftware Take a look at [this Stack Overflow question](https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed). It has a couple of very popular answers that may help you out. – Cheticamp Aug 10 '17 at 11:39