0

我不知道它可能是什么。我在我的代码中搜索了大约 30 分钟

主要活动:

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);
        }
    }

}

显现:

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

那会是什么?意图过滤器是正确的,包是正确的,语音触发是正确的。我只是想让它打印你所说的。我以前做过,但现在不行了!

4

1 回答 1

1

当你重写Activity方法时,不要忘记调用超级方法。

在这里,您正在覆盖onResume()但没有调用超级方法。调用超级方法

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

并在重写任何可读性方法时使用Override注释,并检查NullPointException何时从Intent. 如果没有找到给定键的映射,Intent.getExtras...()将返回null

于 2013-12-12T05:53:53.143 回答