在 Android 中使用 http / https URI 作为内容 URI
我遇到了以下问题。
我的应用程序向用户提供图像库以供选择文件,然后打开输入流以读取该文件并通过某种介质发送它。这是完成工作的代码:
ContentResolver resolver = getContentResolver();
fileStream = resolver.openInputStream(fileUri);
当所选图像驻留在设备存储上(例如从相机拍摄的照片等)并且我得到一个 content:// 方案 URI 时,一切都运行良好。问题是,当我从 Picasa 相册中选择图像时,它显然会按需从 Picasa 服务器加载图像。在这种情况下,我得到一个 https:// 方案 URI,并且 openInputStream
调用失败,并出现 FileNotFoundException“无内容提供程序”。
我的问题是在这种情况下获取输入流的最佳方法是什么?我正在考虑打开 URL 连接,但我想知道这是否是最佳选择?我非常不确定Android中的内容提供商是否可以为此提供更好的解决方案。
I came upon the following issue.
My application presents the image Gallery to the user for selecting a file and then opens an input stream for reading that file and sending it over some medium. This is the code that does the work:
ContentResolver resolver = getContentResolver();
fileStream = resolver.openInputStream(fileUri);
Everything works great when the selected image resides on the device storage (like photos taken from the camera and such) and I get a content:// scheme URI. The problem is when I select an image from my Picasa album which apparently loads the image from the Picasa servers on demand. In that case I get an https:// scheme URI and the openInputStream
call fails with a FileNotFoundException "No content provider".
My question is what would be the best way to get an input stream in that case? I was thinking about opening a URL connection but I wonder if that would be the best option? I am quite unsure on whether content providers in Android can provide a better solution for this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
content:// url 标识本地设备上的资源。
https:// 标识远程服务器(picasa 网络服务器)上的内容。我假设您看到这些是因为您有一台 HTC 设备,其中 picasa 已通过 sense 集成到图库中。
当您获得 https:// 地址时,您需要直接从服务器获取数据。
请参阅 google-api-java-client。
content:// urls identify a resource on the local device.
https:// identifies content on a remote server (The picasa webserver). I assume you're seeing these because you have an HTC device where picasa is integrated into gallery by sense.
When you get a https:// address, you'll need to go fetch the data directly from the server.
See google-api-java-client.