我按照这个站点的示例来消除静态与非静态方法的问题。
public static void startVoiceRecognitionActivity() {
Log.d("Buttons","Start voice called in buttons");
Buttons demo = new Buttons();
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo...");
Log.d("Buttons","Intent to start the command is: " +intent);
demo.startActivityForResult(intent,VOICE_RECOGNITION_REQUEST_CODE);
}
此代码在主要活动中有效,但demo.startActivityForResult(intent,VOICE_RECOGNITION_REQUEST_CODE);
在“按钮”服务类中生成以下错误:
按钮类型的 startActivityForResult(Intent, int) 方法未定义
谁能告诉我我做错了什么?
谢谢!