使用未发布的应用程序进行Google即时语音搜索测试

时间:2017-11-16 13:33:35

标签: android adb google-now google-voice-search

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

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

searchable.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命令有问题吗?请帮忙。

0 个答案:

没有答案