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

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


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.


As I understand it, a use case could be the following:

App A contains the content provider. App B uses that content provider to retrieve all the data items from App A. The user then picks one of these (in App B) and after that an activity in App A to show/edit/delete the selected data item should be started. So App B then creates an intent, and to make sure that an activity in App A handles it, you need to set the (mime-)type of the intent to the mime-type of the uri (the show/edit/delete activities in App A has added this mime type to their intent filters).