返回映射的InputStream从内容提供者的记忆? [英] Returning a memory mapped InputStream from a content provider?

查看:147
本文介绍了返回映射的InputStream从内容提供者的记忆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

内容提供商的消费者,我可以做这样的事情,才能得到正确的InputStream中读取图片的客户端:

The the client side of a content provider consumer I can do something like this, to get a proper InputStream for reading the picture:

InputStream is = getContentResolver().openInputStream(pictureUri);

这是一个很好的API,并会在服务器端,实际内容提供商导致调用:

It is a nice API, and will on the server side, the actual content provider result in a call to:

public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
  // Open a proper ParcelFileDescriptor, most likely using openFileHelper(uri, mode)
}

但是,如果映射到URI中的图像不是要在文件系统中发现,但作为存储器资源,或在飞行中产生

But what if the picture mapped to the URI is not to be found on the filesystem, but as a memory resource, or generated on the fly.

我可以创建映射到内存文件的InputStream ,或其他任何东西,所以,我不要求保存临时文件保存到磁盘,只为了能够将其返回到我的内容提供商的消费者?

Can I create a memory mapped File or InputStream, or anything else, so that I am not required to save a temporary file to disk, just to be able to return it to my content provider consumer?

推荐答案

由于Android的9,你可以使用ParcelFileDescriptor制作一个烟斗。您可以东西最多的是64K,并用它做,或者你可以建立另一个线程来填充它被读取之后。一看便知这里更多的细节:

As of android-9, you can make a pipe using ParcelFileDescriptor. You can stuff up to 64k in it and be done with it, or you can set up another thread to fill it after its been read. See the answer here for more detail:

<一个href="http://stackoverflow.com/questions/2148301/custom-content-provider-openinputstream-openoutputstream/14734310#14734310">Custom内容提供商 - openInputStream(),openOutputStream()

这篇关于返回映射的InputStream从内容提供者的记忆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆