Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use ContentProvider.getType() to get MIME type?

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

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?

like image 634
rogerkk Avatar asked Mar 18 '11 11:03

rogerkk


1 Answers

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.

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

This is pseudocode, but I hope you will got the idea.

like image 96
Vladimir Ivanov Avatar answered Sep 21 '22 07:09

Vladimir Ivanov