简体   繁体   English

Android:其他应用程序无法访问我的应用程序内的文件

[英]Android: Other apps unable to access file inside my app

其他应用程序如 Microsoft Office、pdf 查看器无法打开我的应用程序的“/file”目录中的文件。

I have been providing the Uri of the file through我一直通过提供文件的 Uri

Uri uri = Uri.fromFile(file);

and I think that it was the wrong way of doing it, instead what you should be using is this我认为这是错误的做法,而不是你应该使用的是这个

File file = new File(context.getFilesDir(), "/down.xls");
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", file);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
browserIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(browserIntent);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM