簡體   English   中英

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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM