使用SearchManager的的SUGGEST_COLUMN_ICON_1显示本地文件 [英] Using SearchManager's SUGGEST_COLUMN_ICON_1 to display a local file

查看:332
本文介绍了使用SearchManager的的SUGGEST_COLUMN_ICON_1显示本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现我自己的 SearchRecentSuggestionsProvider 键,除了一件事一切的工作:我不能让设备搜索,显示结果的图标。我想,以显示我的应用程序的数据文件夹的图像(位于 / {} SD卡/ Android的/数据/包名/文件/

I'm implementing my own SearchRecentSuggestionsProvider and everything's working except one thing: I can't get the device search to display icons for the results. I'd like to display images from my application's data folder (located at /{sdcard}/Android/data/package_name/files/)

根据文档,这是可以实现的,通过使用 SearchManager.SUGGEST_COLUMN_ICON_1 ,它显然支持多项计划,包括 ContentResolver.SCHEME_FILE ,这是文件。下面是来自官方的文档报价:

According to the documentation, it's achievable by using SearchManager.SUGGEST_COLUMN_ICON_1, and it apparently supports a number of schemes, including ContentResolver.SCHEME_FILE, which is file. Here's a quote from the official docs:

有关建议光标列名。 可选。的如果你的光标包含此列,那么所有的建议将在包括两个小图标,一个在左,一个在每个建议的权利空间的格式提供。该列中的数据必须是可绘制的资源ID,或以以下格式之一的URI:

Column name for suggestions cursor. Optional. If your cursor includes this column, then all suggestions will be provided in a format that includes space for two small icons, one at the left and one at the right of each suggestion. The data in the column must be a resource ID of a drawable, or a URI in one of the following formats:

含量( SCHEME_CONTENT

android.resource( SCHEME_ANDROID_RESOURCE

android.resource (SCHEME_ANDROID_RESOURCE)

文件( SCHEME_FILE

我已经尝试了一些明显的事情,包括手动创建该文件的URI,并自动创建使用 Uri.Builder()。这一切都不奏效。

I've tried a number of obvious things, including manual creation of the file URI and automated creation using Uri.Builder(). None of this worked.

我还发现有人询问在谷歌论坛同样的事情,它是可悲的是没有答案:的 https://groups.google.com/forum/#​​!topic/android-developers/MJj7GIaONjc

I also found someone else asking about the same thing on Google Groups, and it's sadly unanswered: https://groups.google.com/forum/#!topic/android-developers/MJj7GIaONjc

有没有人有在获得设备搜索到从设备上显示本地图片的经验吗?

Does anyone have any experience in getting the device search to display local images from the device?

UPDATE(12月15日):
我只用试过的ContentProvider 搜索查看作为搜索信息,它的工作原理完全如预期 - 包括封面图片。尽管如此,全局搜索不显示它...

UPDATE (December 15): I've just tried using the ContentProvider with a SearchView as the searchable info, and it works exactly as expected - including the cover art images. Still, global search doesn't show it...

推荐答案

我也有类似的问题,不能让其他解决方案的工作。我终于取代光标,包含我需要在查询中的数据()一个新的。

I had a similar issue and could not make the other solutions work. I finally substituted the cursor with a new one containing the data I needed in query().

public class RecentQueriesProvider extends SearchRecentSuggestionsProvider {
    public final static String AUTHORITY = "com.package.RecentQueriesProvider";
    public final static int MODE = DATABASE_MODE_QUERIES;

    public RecentQueriesProvider() {
        setupSuggestions(AUTHORITY, MODE);
    }

    // We override query() to replace the history icon in the recent searches suggestions. We create a new cursor
    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
        Cursor superCursor = super.query(uri, projection, selection, selectionArgs, sortOrder);
        Uri iconUri = Uri.parse("android.resource://" + getContext().getPackageName() + "/drawable/ic_action_time");
        MatrixCursor newCursor = new MatrixCursor(superCursor.getColumnNames());
        superCursor.moveToFirst();
        while (superCursor.moveToNext()){
            newCursor.addRow(new Object[]{
                    superCursor.getInt(superCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_FORMAT)),
                    iconUri,
                    superCursor.getString(superCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1)),
                    superCursor.getString(superCursor.getColumnIndex("suggest_intent_query")),
                    superCursor.getInt(superCursor.getColumnIndex("_id"))
            });
        }
       return newCursor;
    }
}

这篇关于使用SearchManager的的SUGGEST_COLUMN_ICON_1显示本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆