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.