1

我正在尝试将语音搜索与我的应用程序集成,以便我的 SearchActivity(这不是我的启动器活动)。为此,我已经完成了以下步骤:

AndroidManifest.xml

    <activity
        android:name=".ui.product.VoiceProductSearchActivity"
        android:label="@string/title_activity_product_list"
        android:screenOrientation="portrait">
        <intent-filter>
          <action android:name="com.google.android.gms.anctions.SEARCH_ACTION"/>
          <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <intent-filter>
          <action android:name="android.intent.action.SEARCH"/>
        </intent-filter>
        <meta-data android:name="android.app.searchable"
                   android:resource="@xml/searchable" />
   </activity>

可搜索的.xml

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:hint="@string/search_hint"
    android:includeInGlobalSearch="true"
    android:label="@string/app_name"
    android:searchSuggestAuthority="dictionary" />

VoiceProductSearchActivity.java

public class VoiceProductSearchActivity extends BaseActivity {

    private static final String ACTION_VOICE_SEARCH = "com.google.android.gms.actions.SEARCH_ACTION";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_voice_product_search);
        if (getIntent() != null)
            handleVoiceSearch(getIntent());
        else{
           ........   
        }
    }

    private void handleVoiceSearch(Intent intent) {
        if (intent != null && ACTION_VOICE_SEARCH.equals(intent.getAction())) {
            String query = intent.getStringExtra(SearchManager.QUERY);
            Log.d("voice query", query);

            Toast.makeText(this, query, Toast.LENGTH_LONG).show();
            ...............
            ................
     }
   }
}

现在我尝试以不同的方式测试 adb 命令的功能,例如:

adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION \ --es query "Jackets" com.ecomm.app

adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION -e query "Jackets" com.ecomm.app

每次它返回错误时:

Activity not started, unable to resolve Intent { act=com.google.android.gms.actions.SEARCH_ACTION flg=0x10000000 pkg=\ }

我是否遗漏了编码中的任何内容或 ADB 命令有任何问题?请帮忙。

4

0 回答 0