I put a log in getType() method it never gets printed. I am using the Notepad sample code. Please explain the 1st line of Java doc comment. Returning null from getType() is also working fine. What is the purpose of getType() method?
/** * This is called when a client calls {@link android.content.ContentResolver#getType(Uri)}. * Returns the MIME data type of the URI given as a parameter. * * @param uri The URI whose MIME type is desired. * @return The MIME type of the URI. * @throws IllegalArgumentException if the incoming URI pattern is invalid. */ @Override public String getType(Uri uri) { Log.d("Suparna", "******getType()"); /*switch(uriMatcher.match(uri)) { // ---get all books--- case BOOK_DETAILS: return Book.Book_Details.CONTENT_TYPE; // ---get a particular book--- case BOOK_DETAILS_ID: return Book.Book_Details.CONTENT_ITEM_TYPE; default: throw new IllegalArgumentException("Unsupported URI: " + uri); }*/ return null; }
A content provider manages access to a central repository of data. A provider is part of an Android application, which often provides its own UI for working with the data. However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object.
To access the data from a content provider, URI is used as a query string. Details of different parts of Content URI: content:// – Mandatory part of the URI as it represents that the given URI is a Content URI. authority – Signifies the name of the content provider like contacts, browser, etc.
Content providers are one of the primary building blocks of Android applications, providing content to applications. They encapsulate data and provide it to applications through the single ContentResolver interface. A content provider is only required if you need to share data between multiple applications.
After creating the content provider , specify the content provider in the manifest file. You can mention content provider using the tag. Inside the provider tag dont forget to mention the name and authorities attributes. This declaration should be ..
getType(Uri uri)
will usually only be called after a call to ContentResolver#getType(Uri uri)
. It is used by applications (either other third-party applications, if your ContentProvider
has been exported, or your own) to retrieve the MIME type of the given content URL. If your app isn't concerned with the data's MIME type, it's perfectly fine to simply have the method return null
.
This ContentProvider
's getType()
method is used mostly when you allow your ContentProvider
to interact with other third party applications. This MIME Type is used by Android System to find which applications can handle it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With