Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 意图操作.VIEW失败_Android_Android Intent_Android Manifest_Android Contentprovider_Android Search - Fatal编程技术网

Android 意图操作.VIEW失败

Android 意图操作.VIEW失败,android,android-intent,android-manifest,android-contentprovider,android-search,Android,Android Intent,Android Manifest,Android Contentprovider,Android Search,我最近创建了搜索建议,但现在我面临一个奇怪的问题。我在searchable.xml中设置了android:searchSuggestIntentAction=“android.intent.action.VIEW”并在清单中设置了 <intent-filter> <action android:name="android.intent.action.VIEW" /> </intent-filter> to

我最近创建了搜索建议,但现在我面临一个奇怪的问题。我在searchable.xml中设置了
android:searchSuggestIntentAction=“android.intent.action.VIEW”
并在清单中设置了

<intent-filter>
                <action android:name="android.intent.action.VIEW" />
            </intent-filter> to a activity, which I want to open when the click on suggestion is performed.

我希望在执行单击建议时打开的活动。
结果是它打开了另一个活动-活动,在这里我显示结果,当提交查询时,这个意图过滤器放置在哪里
…SEARCH/>

单击建议时,有没有办法打开不同的活动

MyAndroidManifest.xml-检查//注释

<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: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" //I want to open this
            android:label="@string/title_activity_more"       //activity when is the
            android:launchMode="singleTop"                     //suggestion clicked
            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" //Activity which shows
            android:label="@string/title_activity_search"       //results, when the
            android:launchMode="singleTask"                   //query is submitted
            android:parentActivityName="com.example.animalist.MainActivity" 
            android:screenOrientation="portrait" > //but also appears on sugg. click
            <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>

//但也出现在sugg上。点击
mysearchable.xml

<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"

为什么扩展ContentProvider{而不是扩展SearchRecentSuggestionsProvider{我可以使用recentquerysuggestionadapter提供自定义建议?
public class SuggestionProvider extends ContentProvider {
    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
    };

    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");
    }
}