0

I have no idea what it could be. I searched through my code for like 30 min

MainActivity:

public class MainActivity extends Activity {

public void onResume(){
    ArrayList<String> voiceResults = getIntent().getExtras()
            .getStringArrayList(RecognizerIntent.EXTRA_RESULTS);

    if (voiceResults.size() >= 1) {
        String infoId = "That is what you said";
        Card ShowDataCard = new Card(this);
        ShowDataCard.setText(voiceResults.get(0));
        //ShowDataCard.setText("Testing");
        ShowDataCard.setInfo(infoId);
        View ShowDataCardView = ShowDataCard.toView();
        setContentView(ShowDataCardView);
    }
    else {
        String mainText = "You did not say anything.";
        String infoId = "Why didn't you say anything?";
        Card ShowDataCard = new Card(this);
        ShowDataCard.setText(mainText);
        ShowDataCard.setInfo(infoId);
        View ShowDataCardView = ShowDataCard.toView();
        setContentView(ShowDataCardView);
        }
    }

}

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.glass.texttospeech"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="15" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name="com.example.glass.texttospeach.MainActivity"
        android:label="@string/app_name"
        android:icon="@drawable/icon" >
        <intent-filter>
            <action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
        </intent-filter>
        <meta-data android:name="com.google.android.glass.VoiceTrigger"
            android:resource="@xml/voice_trigger_start" />
     </activity>
</application>

So what could it be? The intent filters are correct, the packages are correct, voice trigger is correct. I am just trying to have it print what you said. I have done it before but it will not work now!

Vincent Taglia
  • 173
  • 1
  • 3
  • 12

1 Answers1

1

when you are overriding Activity methods, don't forget to call super methods.

here you are overriding onResume() but not calling super method. call super method like

 @Override
 public void onResume() {
     super.onResume();
     // do your work....
 }

and use Override annotation when you are overriding any method for readability and check for NullPointException when you are getting extras from Intent. Intent.getExtras...() will return null if there is no mapping found for a given key

Gopal Gopi
  • 11,101
  • 1
  • 30
  • 43