我正在尝试为搜索对话框提供自定义建议。我正在使用 urimatcher 来匹配 uri。但它不起作用。我总是得到异常“java.lang.IllegalArgumentException: Unknown Uri: content://com.simple.search.SuggestionProvider/search_suggest_query/?limit=50”。请向我解释一下。我该怎么做才能解决这个问题?
private static final UriMatcher sURIMatcher = makeUriMatcher();
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
// Use UriMatcher, to find out what type of request received. Next, form
// the corresponding query to the database
switch (sURIMatcher.match(uri)) {
case SEARCH_SUGGEST:
if (selectionArgs == null) {
throw new IllegalArgumentException(
"selectionArgs must be provided for the Uri: " + uri);
}
return getSuggestions(selectionArgs[0]);
case SEARCH_TESTS:
if (selectionArgs == null) {
throw new IllegalArgumentException(
"selectionArgs must be provided for the Uri: " + uri);
}
return search(selectionArgs[0]);
case GET_TEST:
return getRecord(uri);
default:
throw new IllegalArgumentException("Unknown Uri: " + uri);
}
制作Urimatcher
private static UriMatcher makeUriMatcher() {
UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
// For the record
matcher.addURI(AUTHORITY, "tests", SEARCH_TESTS);
matcher.addURI(AUTHORITY, "tests/#", GET_TEST);
// For suggestions table
matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY,
SEARCH_SUGGEST);
matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*",
SEARCH_SUGGEST);
return matcher;
}
日志
11-30 14:16:27.295: I/ActivityThread(1638): Publishing provider com.simple.search.SuggestionProvider: com.simple.search.SuggestionProvider
11-30 14:16:35.424: D/com.simple.search.com.simple.search.SuggestionProvider(1638): Unknown Uri: content://com.simple.search.SuggestionProvider/search_suggest_query/?limit=50
11-30 14:16:35.424: E/DatabaseUtils(1638): Writing exception to parcel
11-30 14:16:35.424: E/DatabaseUtils(1638): java.lang.IllegalArgumentException: Unknown Uri: content://com.simple.search.SuggestionProvider/search_suggest_query/?limit=50
11-30 14:16:35.424: E/DatabaseUtils(1638): at com.simple.search.SuggestionProvider.query(SuggestionProvider.java:122)
11-30 14:16:35.424: E/DatabaseUtils(1638): at android.content.ContentProvider$Transport.bulkQuery(ContentProvider.java:117)
11-30 14:16:35.424: E/DatabaseUtils(1638): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:98)
11-30 14:16:35.424: E/DatabaseUtils(1638): at android.os.Binder.execTransact(Binder.java:287)
11-30 14:16:35.424: E/DatabaseUtils(1638): at dalvik.system.NativeStart.run(Native Method)
searchable.xml
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="@string/search_hint"
android:label="@string/app_label"
android:searchSuggestAuthority="com.simple.search.SuggestionProvider"
android:searchSuggestIntentAction="android.intent.action.VIEW"
android:searchSuggestIntentData="content://com.simple.search.SuggestionProvider/tests"
/>
list
....
....
<activity
android:label="@string/app_name"
android:name=".SimpleSearch" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
....
....
最佳答案
为避免讨论,如果您提供更多信息,我将更改此答案...
但是现在...
你在 xml 中有 android:searchSuggestIntentData="content://com.simple.search.SuggestionProvider/tests"
所以你必须改变
private static UriMatcher makeUriMatcher() {
UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
// For the record
matcher.addURI(AUTHORITY, "tests", SEARCH_TESTS);
matcher.addURI(AUTHORITY, "tests/#", GET_TEST);
// For suggestions table
matcher.addURI(AUTHORITY, "tests/" + SearchManager.SUGGEST_URI_PATH_QUERY,
SEARCH_SUGGEST);
matcher.addURI(AUTHORITY, "tests/" + SearchManager.SUGGEST_URI_PATH_QUERY + "/*",
SEARCH_SUGGEST);
return matcher;
}
如果你没有看到差异,我添加了“tests/”
所以现在它将匹配 content://com.simple.search.SuggestionProvider/tests/search_suggest_query?limit=50 这正是 QSB 将发送的...
无论如何你可以/应该为你的查询添加限制
case SEARCH_SUGGEST:
if (selectionArgs == null) {
throw new IllegalArgumentException(
"selectionArgs must be provided for the Uri: " + uri);
}
final String limit = uri.getQueryParameter(SearchManager.SUGGEST_PARAMETER_LIMIT);
return getSuggestions(selectionArgs[0], limit);
然后在getSuggestions中
helper.getReadableDatabase().query(table, projection,
selection, selectionArgs, null, null, sortOrder, limit);
编辑:
AUTHORITY + "tests/"+ SearchManager.SUGGEST_URI_PATH_QUERY 应该和 android:searchSuggestIntentData 一样!!!
EDIT2: 来自文档 http://developer.android.com/guide/topics/search/adding-custom-suggestions.html
selection The value provided in the android:searchSuggestSelection attribute of your searchable configuration file, or null if you have not declared the android:searchSuggestSelection attribute. More about using this to get the query below. selectionArgs Contains the search query as the first (and only) element of the array if you have declared the android:searchSuggestSelection attribute in your searchable configuration. If you have not declared android:searchSuggestSelection, then this parameter is null. More about using this to get the query below.
添加 android:searchSuggestSelection="? "
关于android - UriMatcher 不会匹配 uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8394119/
设置:狂欢ruby1.9.2高线(1.6.13)描述:我已经相当习惯在其他一些项目中使用highline,但已经有几个月没有使用它了。现在,在Ruby1.9.2上全新安装时,它似乎不允许在同一行回答提示。所以以前我会看到类似的东西:require"highline/import"ask"Whatisyourfavoritecolor?"并得到:Whatisyourfavoritecolor?|现在我看到类似的东西:Whatisyourfavoritecolor?|竖线(|)符号是我的终端光标。知道为什么会发生这种变化吗? 最佳答案
在我的应用程序中,我需要能够找到所有数字子字符串,然后扫描每个子字符串,找到第一个匹配范围(例如5到15之间)的子字符串,并将该实例替换为另一个字符串“X”。我的测试字符串s="1foo100bar10gee1"我的初始模式是1个或多个数字的任何字符串,例如,re=Regexp.new(/\d+/)matches=s.scan(re)给出["1","100","10","1"]如果我想用“X”替换第N个匹配项,并且只替换第N个匹配项,我该怎么做?例如,如果我想替换第三个匹配项“10”(匹配项[2]),我不能只说s[matches[2]]="X"因为它做了两次替换“1fooX0barXg
如何匹配未被反斜杠转义的平衡定界符对(其本身未被反斜杠转义)(无需考虑嵌套)?例如对于反引号,我试过了,但是转义的反引号没有像转义那样工作。regex=/(?!$1:"how\\"#expected"how\\`are"上面的正则表达式不考虑由反斜杠转义并位于反引号前面的反斜杠,但我愿意考虑。StackOverflow如何做到这一点?这样做的目的并不复杂。我有文档文本,其中包括内联代码的反引号,就像StackOverflow一样,我想在HTML文件中显示它,内联代码用一些spanMaterial装饰。不会有嵌套,但转义反引号或转义反斜杠可能出现在任何地方。
我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘
我有一个驼峰式字符串,例如:JustAString。我想按照以下规则形成长度为4的字符串:抓取所有大写字母;如果超过4个大写字母,只保留前4个;如果少于4个大写字母,则将最后大写字母后的字母大写并添加字母,直到长度变为4。以下是可能发生的3种情况:ThisIsMyString将产生TIMS(大写字母);ThisIsOneVeryLongString将产生TIOV(前4个大写字母);MyString将生成MSTR(大写字母+tr大写)。我设法用这个片段解决了前两种情况:str.scan(/[A-Z]/).first(4).join但是,我不太确定如何最好地修改上面的代码片段以处理最后一种
我真的为这个而疯狂。我一直在搜索答案并尝试我找到的所有内容,包括相关问题和stackoverflow上的答案,但仍然无法正常工作。我正在使用嵌套资源,但无法使表单正常工作。我总是遇到错误,例如没有路线匹配[PUT]"/galleries/1/photos"表格在这里:/galleries/1/photos/1/edit路线.rbresources:galleriesdoresources:photosendresources:galleriesresources:photos照片Controller.rbdefnew@gallery=Gallery.find(params[:galle
我已经在mountainlion上成功安装了rbenv和rubybuild。运行rbenvinstall1.9.3-p392结束于:校验和不匹配:ruby-1.9.3-p392.tar.gz(文件已损坏)预期f689a7b61379f83cbbed3c7077d83859,得到1cfc2ff433dbe80f8ff1a9dba2fd5636它正在下载的文件看起来没问题,如果我使用curl手动下载文件,我会得到同样不正确的校验和。有没有人遇到过这个?他们是如何解决的? 最佳答案 tl:博士;使用浏览器从http://ftp.rub
@raw_array[i]=~/[\W]/非常简单的正则表达式。当我用一些非拉丁字母(具体来说是俄语)尝试时,条件是错误的。我能用它做什么? 最佳答案 @raw_array[i]=~/[\p{L}]/使用西里尔字符进行测试。引用:http://www.regular-expressions.info/unicode.html#prop 关于ruby-正则表达式将非英文字母匹配为非单词字符,我们在StackOverflow上找到一个类似的问题: https://
前言一般来说,前端根据后台返回code码展示对应内容只需要在前台判断code值展示对应的内容即可,但要是匹配的code码比较多或者多个页面用到时,为了便于后期维护,后台就会使用字典表让前端匹配,下面我将在微信小程序中通过wxs的方法实现这个操作。为什么要使用wxs?{{method(a,b)}}可以看到,上述代码是一个调用方法传值的操作,在vue中很常见,多用于数据之间的转换,但由于微信小程序诸多限制的原因,你并不能优雅的这样操作,可能有人会说,为什么不用if判断实现呢?但是if判断的局限性在于如果存在数据量过大时,大量重复性操作和if判断会让你的代码显得异常冗余。wxswxs相当于是一个独立
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路