我正在为我的应用程序编写一个应用程序更新程序。在此之后,我确保设备上有我自己的旧apk,更新程序在MARSH MALLOW和NOUGAT版本更新之前运行得很好,它显示了错误,这是我试图更新的应用程序中所做的:
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();
}当尝试打开新的现有apk时,应用程序会崩溃。
这是错误日志:
android.os.FileUriExposedException: file:///storage/emulated/0/.fTouch_app/Ftouch.jpg exposed beyond app through Intent.getData()感谢你的help.Thank。
发布于 2017-08-10 11:24:03
这看起来像你的问题。
来自FileUriExposedException的文档
当应用程序向另一个应用程序公开文件:// Uri时引发的异常。 由于接收应用程序可能无法访问共享路径,因此不鼓励这种公开。例如,接收应用程序可能没有请求READ_EXTERNAL_STORAGE运行时权限,或者平台可能跨用户配置文件边界共享Uri。 相反,应用程序应该使用内容:// Uris,这样平台就可以扩展接收应用程序访问资源的临时权限。 这只对以N或更高为目标的应用程序抛出。允许针对早期SDK版本的应用程序共享文件:// Uri,但强烈禁止共享文件。
https://stackoverflow.com/questions/45612238
复制相似问题