Android ContentProvider getType() 在何时以及为何调用
2022-09-01 18:49:39
我把一个日志放在getType()方法中,它永远不会被打印出来。我正在使用记事本示例代码。请解释 Java 文档注释的第一行。从 getType() 返回 null 也工作正常。getType() 方法的用途是什么?
/**
* 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;
}