gpt4 book ai didi

java - Android ContentProvider getType() 调用的时间和原因

转载 作者:IT老高 更新时间:2023-10-28 20:39:52 25 4
gpt4 key购买 nike

我在 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;
}

最佳答案

getType(Uri uri) 通常只会在调用 ContentResolver#getType(Uri uri) 之后调用。应用程序(其他第三方应用程序,如果您的 ContentProvider 已导出,或者您自己的应用程序)使用它来检索给定内容 URL 的 MIME 类型。如果您的应用不关心数据的 MIME 类型,则只需使用 return null 方法就可以了。

关于java - Android ContentProvider getType() 调用的时间和原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12297527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com