次のように RecognitionListener を実装するクラスがあります。
public class listener implements RecognitionListener
アラートダイアログを表示してバイブレーターを使用したかったのですが、持っていないコンテキストを提供する必要があるため、これは不可能です。
私のアラートダイアログコードは次のようなものでした:
new AlertDialog.Builder(this)
.setTitle("dd")
.setMessage("aa")
.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
しかし、 AlertDialog.Builder(this) にはコンテキストが必要です。これは、私のバイブレーター コードと同じ問題です。
v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
getSystemService メソッドは使用できません。
クラスを開始する私のコード:
sr = SpeechRecognizer.createSpeechRecognizer(this);
sr.setRecognitionListener(new listener());
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5);
sr.startListening(intent);
これを解決する最良の方法は何ですか?