- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
在我的 Andoroid 应用程序中,我想让用户使用用户喜欢的任何发送方法(例如电子邮件、Skype、Viber、蓝牙等)发送我的应用程序生成的文件我正在使用 Intent.ACTION_SEND 如下:
File readF = new File(fullFileName);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.some_subject));
intent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.some_message_body));
Uri uri = FileProvider.getUriForFile(this, "my.package.fileprovider", readF);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, getResources().getString(R.string.some_info_message));
正如预期的那样,它成功地通过 Gmail 和蓝牙发送了文件。
但是当用户选择Skype时,文件被发送了,但是它的名字被改变了
当用户选择 Viber 时,不会发送任何内容。
如果我只改变构建 Uri 的方式:
Uri uri = Uri.fromFile(new File("/some/publicly/available/file"));
然后文件通过 Skype 和 Viber 成功发送,名称被保留。
那么在 Intent 中使用 FileProvider 与直接使用公共(public)文件有什么区别。
最佳答案
I am using Intent.ACTION_SEND as follows:
我建议您将 Intent.FLAG_GRANT_READ_URI_PERMISSION
添加到该 Intent
。
Then the file is successfully sent both over Skype, and Viber, and the name is preserved.
直到您的 targetSdkVersion
攀升至 24 或更高,您才开始在 Android 7.0+ 上运行您的应用程序。然后,您的应用程序崩溃并出现 FileUriExposedException
。
Then the file is successfully sent both over Skype, and Viber, and the name is preserved.
现在,也许。这些应用程序的作者和任何其他人没有义务维护您的文件名。他们可以为所欲为,因为这是他们的应用程序,而不是您的。
So what is the difference in using FileProvider vs directly using a public file in Intent.
FileProvider
大致类似于 Web 服务器。它允许一个应用程序与其他应用程序共享内容,而这些应用程序不必直接访问底层文件。 Google 正试图避免让外部存储成为随机垃圾的垃圾场,以支持诸如 ACTION_SEND
之类的东西,因此在 Android 7.0+ 上设置了 StrictMode
“如果您尝试传递 file
Uri
(例如,Uri.fromFile()
),开箱即用”会使应用程序崩溃。
关于android - FileProvider.getUriForFile vs Uri.fromFile - 除了权限之外还有其他区别吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42796774/
我使用 Intent 发送文件的代码不适用于所有文件源,我还找不到解决方案: 我的应用程序已注册用于打开文件,因此当我在 ES 文件资源管理器中选择一个文件时, Intent 如下所示: intent
我正在制作一个应用程序,我需要拍照,然后将一些数据保存到数据库中,但是当我尝试从照片中获取 URI 时出现此错误: java.lang.IllegalArgumentException: Failed
FileProvider.getUriForFile 返回一个空对象引用,我不知道为什么。这以前有效。以下错误是我得到的。我还在错误下方添加了我的代码。 Process: com.example.jo
所以我正在开发一个应用程序,我会在其中拍照并尝试将其保存到应用程序的内部存储空间中。我在使用文件提供程序时遇到问题。我已经看过许多关于堆栈溢出的问题,但如果可能的话,我想得到更详细的解释。 我也按照谷
首先要提的是,问题的答案here不帮忙。 源代码如下所示: Intent intent = new Intent("com.mycompany.action.PICK_FILE"); Strin
在我的应用中,尝试使用相机应用捕捉图像。我正在更新我的应用程序以在指定用于保存图像的文件路径时使用 FileProvider.getUriForFile,因为 Uri.fromFile 已被弃用。 使
你能帮我调试我的应用程序吗,它构建时没有错误,但是一旦我单击“更改个人资料图片”加载相机(就像 Instagram 上用于更改个人资料图片的按钮),我的应用程序就会停止。 我将不胜感激任何帮助,谢谢
我已经更新了我的项目以实现Providers。整个实现似乎是正确的,但我在 FileProvider 类中收到了一个 StringIndexOutOfBoundsException 异常。 在我的例子
我正在尝试编写我的第一个 Android 应用程序,它将涉及拍照和处理照片。 我在网上看了几个教程后整理了一些代码,但是每当单击按钮时我都会收到以下 NullPointerException: 10-
我按照 android developer reference on FileProviders 上的示例代码进行操作但它不会工作。 我在 Manifest 的文件提供程序定义中设置了路径 files
在我的应用中使用 FileProvider.getUriForFile 时出现仅在华为设备上发生的异常: Exception: java.lang.IllegalArgumentException:
长话短说 我想通过 FileProvider 获取(读取/生成)文件 Uri - 路径如下 - 但不知道如何: val file = File("/external/file/9359") // ho
我正在尝试实现一个 FileProvider 以允许我与电子邮件和其他应用程序共享本地私有(private)图像。我一直按照 Android 开发人员指南的说明进行操作,并深入了解必须使用“getUr
目前,当文件位于外部 SD 上时,FileProvider getUriForFile 方法会生成 IllegalArgumentException 当文件在设备内存中(在/storage/emula
我在 Kotlin 中遇到了奇怪的行为 创建像这样的自定义文件提供程序时 import android.support.v4.content.FileProvider class MyFileProv
在我的 Andoroid 应用程序中,我想让用户使用用户喜欢的任何发送方法(例如电子邮件、Skype、Viber、蓝牙等)发送我的应用程序生成的文件我正在使用 Intent.ACTION_SEND 如
我正在尝试实现一个相机 Activity ,用户可以在其中拍照并将其保存到手机上。 错误: java.lang.IllegalArgumentException: Failed to find con
下面的代码用于尝试文件提供程序,为 Android Nougat 做准备: list 文件:
我一直在尝试关注 Android tutorial关于共享文件。我这样设置 FileProvider: 在主 list xml 上: res/xml/fi
我有来自 this 的代码统一回答代码以安装 apk,但它在 Android 7.0 中不起作用,因为不再支持 Uri.fromfile 并且现在应该使用 FileProvider.getUriFor
我是一名优秀的程序员,十分优秀!