这是比较Intents的正确方法吗?

时间:2012-09-05 09:40:33

标签: android

这是比较Intents的正确方法吗?无论传入的Intentandroid.Intent.action.VIEW(值为intent.getAction()返回),我都没有进入if / else:

    private void handleIntent(Intent intent) {
Log.d(TAG, intent.getAction()); // -> android.Intent.action.VIEW
            if (Intent.ACTION_VIEW.equals(intent.getAction())) {
                ShowToast.showToast(this, "Something..."); // Never get here
            } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
                String query = intent.getStringExtra(SearchManager.QUERY);
                showResults(query);
            }
        }

更新:为什么intent.getAction()会返回android.Intent.action.VIEW(大写'i'),而android.intent.action.VIEW会像specification一样返回{{1}}?< / p>

1 个答案:

答案 0 :(得分:2)

我找到了首都'我'的来源。只要我使用SearchView,我就会指定在Intent新的Activity启动时使用的<searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/appname" android:hint="@string/search_hint" android:searchSuggestAuthority="my.package.dataproviders.TicketSuggestionProvider" android:searchSuggestIntentData="content://my.package.dataproviders.TicketSuggestionProvider/titleslist" android:searchSuggestIntentAction="android.Intent.action.VIEW" // HERE IT IS android:searchSuggestSelection=" ?"> </searchable> ,所以我在这里犯了一个错误:

{{1}}