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 に答える