Android: 其他应用无法访问我的应用内的文件
Android: Other apps unable to access file inside my app
Microsoft office、pdf 查看器等其他应用程序无法打开我的应用程序“/file”目录中的文件。
我一直在通过
提供文件的Uri
Uri uri = Uri.fromFile(file);
而且我认为这是错误的做法,而你应该使用的是这个
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);
Microsoft office、pdf 查看器等其他应用程序无法打开我的应用程序“/file”目录中的文件。
我一直在通过
提供文件的UriUri uri = Uri.fromFile(file);
而且我认为这是错误的做法,而你应该使用的是这个
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);