我正在尝试从 Google Now 获取搜索结果。我已按照http://android-developers.blogspot.com/2014/10/the-fastest-route-between-voice-search.html和https://developer.android.com/guide/components/上的说明进行操作意图-common.html#SearchOnApp。
它通过 ADB 工作,但在我将应用程序发布到 PlayStore 之后就不行了。 当尝试搜索时(“在 Casa Controller 上搜索某些东西),它说它正在打开应用程序,但后来没有。有什么想法吗?
ADB 命令测试
adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION --es query "salad" io.biddleinc.casacontroller
我的 Android 清单
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="20702" android:versionName="2.7.2" android:windowSoftInputMode="adjustPan" package="io.biddleinc.casacontroller" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:exported="true" android:label="@string/app_name" android:launchMode="singleTop" android:name="HelloCordova" android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="com.google.android.gms.actions.SEARCH_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.default_searchable" android:value=".SearchActivity" />
</activity>
<activity android:label="@string/app_name" android:name=".SearchActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable" />
</activity>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="22" />
</manifest>
我的 searchable.xml
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_label"
android:hint="@string/search_hint">
</searchable>
我的strings.xml
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="app_name">Casa Controller</string>
<string name="app_label">Casa Controller</string>
<string name="search_hint">What do you want to happen</string>
</resources>
我的活动.java
package io.biddleinc.casacontroller;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import org.apache.cordova.*;
public class HelloCordova extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
Intent intent = getIntent();
String url = "file:///android_asset/www/login_full.html";
if (Intent.ACTION_SEARCH.equals(intent.getAction())
|| "com.google.android.gms.actions.SEARCH_ACTION".equals(intent.getAction())) {
url += "?search=" + intent.getStringExtra(SearchManager.QUERY);
}
super.loadUrl(url);
// Set by <content src="index.html" /> in config.xml
//super.loadUrl(Config.getStartUrl());
//super.loadUrl("file:///android_asset/www/index.html");
}
@Override
protected void onNewIntent(Intent intent)
{
//super.onNewIntent(intent);
if (Intent.ACTION_SEARCH.equals(intent.getAction())
|| "com.google.android.gms.actions.SEARCH_ACTION".equals(intent.getAction())) {
String phrase = intent.getStringExtra(SearchManager.QUERY);
String url = "javascript: { recongizeSpeechFromGoogle('"+ phrase + "'); }";
super.loadUrl(url);
}
//Forward to plugins
if (this.appView != null)
this.appView.onNewIntent(intent);
}
}