首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Intent.ACTION_VIEW在搜索中不起作用

Intent.ACTION_VIEW在搜索中不起作用
EN

Stack Overflow用户
提问于 2014-02-13 22:19:25
回答 1查看 717关注 0票数 1

当用户单击搜索建议时,我试图设置Intent.ACTION_VIEW。它仍然执行ACTION_SEARCH意图,因此它在“建议”框中搜索提供的信息,但我希望它将其传递给已经显示单击对象的活动。我不使用SearchActivity及其方法(onNewIntent等),我只使用活动,它显示结果列表-它的集合为_default_searchable。

但是,如果需要将它传递给不同的活动,当建议项被选中时,我应该做什么呢?

我在Manifest的第二个活动中将android:searchSuggestIntentAction="android.intent.action.VIEW"和意图过滤器设置为intent.VIEW,但它不起作用

你知道怎么做吗?

searchable.xml

代码语言:javascript
运行
复制
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
        android:label="@string/app_name"
        android:hint="@string/search_hint"
        android:searchSuggestAuthority="com.example.animalist.SuggestionProvider" 
        android:searchSuggestSelection=" ?"
        android:searchSuggestIntentAction="android.intent.action.VIEW"


         />

清单

代码语言:javascript
运行
复制
<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
                <provider
                    android:authorities="com.example.animalist.SuggestionProvider"
                    android:name=".SuggestionProvider" >
                </provider>
        <meta-data android:name="android.app.default_searchable"
                   android:value=".SearchActivity"/>
        <activity
            android:name="com.example.animalist.MainActivity"
            android:label="@string/app_name"
            android:launchMode="singleTop"
            android:screenOrientation="portrait" >
            <meta-data android:name="android.app.default_searchable"
                       android:value=".SearchActivity"/>

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>

        <activity
            android:name="com.example.animalist.MoreActivity"
            android:label="@string/title_activity_more"
            android:launchMode="singleTop"
            android:parentActivityName="com.example.animalist.MainActivity"
            android:screenOrientation="portrait" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.animalist.MainActivity" />

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


        </activity>

        <activity
            android:name="com.example.animalist.SearchActivity"
            android:label="@string/title_activity_search"
            android:launchMode="singleTop"
            android:parentActivityName="com.example.animalist.MainActivity"
            android:screenOrientation="portrait" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.animalist.MainActivity" />


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

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

        </activity>

    </application>

提供程序

代码语言:javascript
运行
复制
public class SuggestionProvider extends SearchRecentSuggestionsProvider {
    private static final String TAG = "SuggestionProvider";

    private static final int SEARCH_SUGGESTIONS = 1;

    private static final UriMatcher sURLMatcher = new UriMatcher(
            UriMatcher.NO_MATCH);

    static {
        sURLMatcher.addURI("*", SearchManager.SUGGEST_URI_PATH_QUERY,
                SEARCH_SUGGESTIONS);
        sURLMatcher.addURI("*", SearchManager.SUGGEST_URI_PATH_QUERY + "/*",
                SEARCH_SUGGESTIONS);
    }

    private static final String[] COLUMNS = new String[] {
            "_id",
            SearchManager.SUGGEST_COLUMN_TEXT_1,
            SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
            SearchManager.SUGGEST_COLUMN_QUERY,
            SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA
    };

    public SuggestionProvider() {
    }

    @Override
    public boolean onCreate() {
        return true;
    }

    @Override
    public Cursor query(Uri url, String[] projectionIn, String selection,
            String[] selectionArgs, String sort) {
        int match = sURLMatcher.match(url);
        switch (match) {
            case SEARCH_SUGGESTIONS:
                String query = url.getLastPathSegment();
                MatrixCursor cursor = new MatrixCursor(COLUMNS);

                ParseQuery<Animal> squery = ParseQuery.getQuery(Animal.class);
            try {

                List<Animal> results = squery.find();
                for (Animal animal : results) {
                        addRow(cursor,  animal.getAnimal());
            } }catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


            return cursor;}
        return null;
                }





    private void addRow(MatrixCursor cursor, String string) {
        long id = cursor.getCount();
        cursor .newRow().add(id).add(string).add(Intent.ACTION_SEARCH).add(string);
    }

    @Override
    public String getType(Uri url) {
        int match = sURLMatcher.match(url);
        switch (match) {
            case SEARCH_SUGGESTIONS:
                return SearchManager.SUGGEST_MIME_TYPE;
            default:
                throw new IllegalArgumentException("Unknown URL: " + url);
        }
    }

    @Override
    public int update(Uri url, ContentValues values, String where, String[] whereArgs) {
        throw new UnsupportedOperationException("update not supported");
    }

    @Override
    public Uri insert(Uri url, ContentValues initialValues) {
        throw new UnsupportedOperationException("insert not supported");
    }

    @Override
    public int delete(Uri url, String where, String[] whereArgs) {
        throw new UnsupportedOperationException("delete not supported");
    }
}

提前感谢您的帮助

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-13 22:33:38

虽然这并不是一个很好的方法,如果,我已经解决了这一点之前,通过一个透明的活动,处理双方的意图,以查看和搜索。

从此活动中,您可以启动要处理任何一种情况并完成透明活动的活动,并传入搜索参数。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21766765

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档