Android 4.4中全局搜索功能未按预期工作

22

我有一个应用程序,其中有两个搜索建议提供程序,它们都扩展了SearchRecentSuggestionsProvider。我已经在清单文件中正确设置了以下的Intent过滤器和元数据:

<intent-filter>
   <action android:name="android.intent.action.SEARCH" />
</intent-filter>

<meta-data
   android:name="android.app.searchable"
   android:resource="@xml/searchable_tv" />

这个可搜索的资源包括 android:includeInGlobalSearch="true",所以应该没问题。

而且我显然也有一个提供者:

<provider
   android:name="com.miz.contentprovider.TvShowContentProvider"
   android:authorities="com.miz.contentprovider.TvShowContentProvider"
   android:exported="true" />

在Android 4.3中使用Google搜索应用程序一切正常,但我刚刚将所有设备升级到Android 4.4,不再能够搜索应用程序内的内容。其他应用程序也是如此,例如Google Play音乐。

我在XDA开发者论坛上找到了一个提到这个问题的帖子,如果有帮助的话: http://forum.xda-developers.com/showthread.php?p=47472102

有人知道发生了什么或如何修复吗?

更新:我可以确认它只会发生在Android 4.4设备上。我使用最新的Google搜索更新在Android 4.3设备上进行了测试,一切正常。看起来这是Google更新中的一个错误。


Google Chrome 应用程序确实出现在列表中。 - nhaarman
似乎只有测试版出现了。 - Michell Bak
显示这不是一个错误,但可能是他们悄悄地加强了过滤器。 - nhaarman
我查看了最新的Chrome beta应用程序的清单文件,没有发现任何差异。他们改变4.4上的过滤器,但不改变4.3是毫无意义的。 - Michell Bak
3
问题跟踪页面链接:https://code.google.com/p/android/issues/detail?id=62251。目前为止,对方还没有确认此问题报告。 - Joe
显示剩余3条评论
3个回答

8

看起来这就是答案。虽然有点遗憾。 - Michell Bak
1
如果你真的依赖这个功能,无论实现方式如何,你可以安装应用程序“QuickSearch”(id=de.jars.android.quicksearch)。这个应用程序以某种方式模拟了电话搜索机制,这样你仍然可以搜索你的应用程序。 缺点是:这个应用程序有广告软件,并且在现代设备上看起来相当丑陋,因为它的主题是Android 2.x风格,没有针对平板电脑进行优化。 - arne.jans

5

我向谷歌的联系人进行了核实,应用索引将取代此功能。文档将更新为已弃用,并且在没有系统级权限的情况下无法在Kit Kat上使用此功能(如上所示)。


2
我不是说这不是真的,但我希望它不是。并非所有应用程序都能利用该功能,它肯定不能替代全局设备搜索。 - Michell Bak
我同意。能够在设备搜索中展示我们的应用程序真是太好了。 - Matthew Runo
这个答案提供了一个链接来证实你所说的,所以我会点赞你的并接受另一个答案:https://dev59.com/1mIj5IYBdhLWcg3wrG4q#21627271 - Michell Bak
我希望事情不是这样的,但似乎应用索引是未来的趋势。如果我们没有一个可以进行应用索引的网站,我不确定我们该怎么办。 - Matthew Runo

1

自从最新更新(v31)后,Google Chrome现在作为可搜索应用程序出现。

系统应用:

试试这样做

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.globalsearch" android:sharedUserId="android.uid.shared">
    <uses-permission android:name="android.permission.GLOBAL_SEARCH" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SET_PREFERRED_APPLICATIONS" />
    <application android:label="@string/global_search" android:process="android.process.acore">
        <activity android:name=".GlobalSearch" android:permission="android.permission.GLOBAL_SEARCH_CONTROL" android:stateNotNeeded="true" android:theme="@android:style/Theme.NoDisplay" android:excludeFromRecents="true">
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <!-- This must be higher than the default priority (0), which
is what GoogleSearch uses. -->
            <intent-filter android:priority="500">
                <action android:name="android.search.action.GLOBAL_SEARCH" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" />
        </activity>
        <activity android:name=".SearchSettings" android:label="@string/search_settings">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.search.action.SEARCH_SETTINGS" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <provider android:name=".SuggestionProvider" android:authorities="com.android.globalsearch.SuggestionProvider" android:permission="android.permission.GLOBAL_SEARCH_CONTROL" />
        <provider android:name=".StatsProvider" android:authorities="com.android.globalsearch.stats" android:permission="android.permission.GLOBAL_SEARCH_CONTROL" />
        <meta-data android:name="android.app.default_searchable" android:value=".GlobalSearch" />
    </application>
</manifest>

据我所知,android.permission.GLOBAL_SEARCH 权限是为系统应用程序而设计的,不能被第三方应用程序使用,因此,如果没有尝试过,我非常确定这不会起作用。 - Michell Bak
@MichellBak 你试过使用Android 4.4的SearchableDictionary示例吗?它对我有效。 - codercat
来自/frameworks/base/core/res/AndroidManifest.xml的android.permission.GLOBAL_SEARCH:<permission android:name="android.permission.GLOBAL_SEARCH" android:permissionGroup="android.permission-group.SYSTEM_TOOLS" android:protectionLevel="signature|system" />实际上这个权限将不会被授予。@iDev,您是否已经检查LogCat/PackageManager.checkPermission,以确保您的应用程序没有被拒绝此权限? - Tom

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接