2

I am trying to get the search result from Google Now. I have followed the instructions on http://android-developers.blogspot.com/2014/10/the-fastest-route-between-voice-search.html and https://developer.android.com/guide/components/intents-common.html#SearchOnApp.

It works through ADB but not after I publish the app to the PlayStore. When trying the search ("Search for something on Casa Controller) it says that that it is opening the app but then doesn't. Any ideas?

ADB Command Tested

adb shell am start -a com.google.android.gms.actions.SEARCH_ACTION --es query "salad" io.biddleinc.casacontroller

My Android Manifest

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

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

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

My Activity.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);
    }


}

1 Answers1

0

Firstly I don't think that you need to override the onNewIntent() method, it's certainly not needed to get the voice recognition working anyway.

Try adding a label to your intent-filter in your xml as below, this did the trick for me.

<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 android:label="@string/app_name">
            <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 android:label="@string/app_name">
            <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" />

If this does not work then try moving your two intent-filter tags into the one activity. Your app may be getting confused as to which activity is supposed to interpret the action.

Make sure that you are running this on a build variant of your app that has been released to the play store. So if your published application id is com.example.myapp then make sure you are not trying to run this test on a debug build com.example.myapp.debug or something like that.

Also note that if your app has an odd name like 'MySup3rC00lApp', or something like that, then Android may not be able to open it up as it will not be able to identify the app.

chuckliddell0
  • 2,061
  • 1
  • 19
  • 25