为什么使用ContentProvider.getType()获取MIME类型? [英] Why use ContentProvider.getType() to get MIME type?
问题描述
综观内容提供商,我不上的getType()方法的典型用法比较干净。该API文档说,有关实施这个方法
Looking at content providers, I'm not quite clean on the typical usage of the getType() method. The API doc says about implementing this method that
这使得[应用]检索MIME 调度时,键入一个URI 意图。
This allows [applications] to retrieve the MIME type for a URI when dispatching intents.
任何人都可以形容的地方使用它是特别有用的一个典型案例?
Could anyone describe a typical case where using it would be particularly useful?
推荐答案
例如,你写的内容提供商的图片库。你应该说在你的getType(),您提供的图片方法 - JPG或PNG。所以,当一个人将推出图片库,它能够显示您的内容提供商提供的内置照片和图片。
For example, you're writing content provider for picture gallery. You should mention in your getType() method that you provide pictures - jpg or png. So, when one will launch image gallery, it will be able to show built-in pictures and pictures provided by your content provider.
在伪$ C C的ContentProvider的用户$做这样的事情:
In pseudocode the user of contentProvider do something like:
List contentProviders = getProviders();
List resultProviders;
final Type type = Type.JPG;
for (ContentProvider provider : contentProviders) {
if (type == provider.getType()) {
resultProviders.add(provider);
}
}
这是伪code,但我希望你能上心。
This is pseudocode, but I hope you will got the idea.
这篇关于为什么使用ContentProvider.getType()获取MIME类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!