为什么我的 ContentProvider 未知?
AndroidManifest.xml 的
<!-- Provides search suggestions for addresses -->
<provider android:name="com.my.app.provider.SearchAddressProvider"
android:authorities="com.my.app.provider.SearchAddressProvider" />
部分
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.app" android:versionCode="1"
android:versionName="1.0">
来自我的提供程序类 SearchAddressProvider
public static final String KEY_ADDRESS_1 = SearchManager.SUGGEST_COLUMN_TEXT_1;
public static final String KEY_ADDRESS_2 = SearchManager.SUGGEST_COLUMN_TEXT_2;
public static final String KEY_MARKER = SearchManager.SUGGEST_COLUMN_ICON_1;
public static final String KEY_FAVORITE = SearchManager.SUGGEST_COLUMN_ICON_2;
private static String AUTHORITY = "com.my.app.provider.SearchAddressProvider";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
+ "/searchaddress");
private static final UriMatcher uriMatcher = buildUriMatcher();
....
@Override
public String getType(Uri uri) {
switch (uriMatcher.match(uri)) {
case SEARCH_WORDS:
return WORDS_MIME_TYPE;
case GET_WORD:
return DEFINITION_MIME_TYPE;
case SEARCH_SUGGEST:
return SearchManager.SUGGEST_MIME_TYPE;
default:
throw new IllegalArgumentException("Unknown URL " + uri);
}
}
但在我的活动中,使用这些定义调用此类,使用以下命令:
Cursor cursor = managedQuery(SearchAddressProvider.CONTENT_URI, null, null, new String[] {query}, null);
我得到IllegalArgumentException Unknown URI
这对我来说是个问题,解决方案吗?
AndroidManifest.xml
<!-- Provides search suggestions for addresses -->
<provider android:name="com.my.app.provider.SearchAddressProvider"
android:authorities="com.my.app.provider.SearchAddressProvider" />
the <manifest ... >
section
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.app" android:versionCode="1"
android:versionName="1.0">
From my provider class SearchAddressProvider
public static final String KEY_ADDRESS_1 = SearchManager.SUGGEST_COLUMN_TEXT_1;
public static final String KEY_ADDRESS_2 = SearchManager.SUGGEST_COLUMN_TEXT_2;
public static final String KEY_MARKER = SearchManager.SUGGEST_COLUMN_ICON_1;
public static final String KEY_FAVORITE = SearchManager.SUGGEST_COLUMN_ICON_2;
private static String AUTHORITY = "com.my.app.provider.SearchAddressProvider";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
+ "/searchaddress");
private static final UriMatcher uriMatcher = buildUriMatcher();
....
@Override
public String getType(Uri uri) {
switch (uriMatcher.match(uri)) {
case SEARCH_WORDS:
return WORDS_MIME_TYPE;
case GET_WORD:
return DEFINITION_MIME_TYPE;
case SEARCH_SUGGEST:
return SearchManager.SUGGEST_MIME_TYPE;
default:
throw new IllegalArgumentException("Unknown URL " + uri);
}
}
yet in my activity that calls this class with those definitions, with this command:
Cursor cursor = managedQuery(SearchAddressProvider.CONTENT_URI, null, null, new String[] {query}, null);
I get IllegalArgumentException Unknown URI
thats a problem for me, solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码:
请注意,您的
UriMatcher
不支持searchaddress
,而是处理dictionary
。所以我认为CONTENT_URI
应该更改为:Your code:
Note, your
UriMatcher
does not supportsearchaddress
, it deals withdictionary
instead. So I think theCONTENT_URI
should be changed to: