我有一个问题,我希望在文本到语音完成发言后启动Android服务。
这是我的代码
num3
HashMap<String, String> myHashAlarm = new HashMap<String, String>();
myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM));
myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "SOME MESSAGE");
t1.speak(text, TextToSpeech.QUEUE_FLUSH, myHashAlarm);
t1.speak("I can speak anything",TextToSpeech.QUEUE_ADD, null);
请帮助我....
答案 0 :(得分:1)
您可以使用标准方式启动服务,但startService()需要上下文,如果您在ProgressListener
内,那将是上下文。
您需要使用
context.startService(new Intent(context, MyService.class));
如果您使用的是活动,则可以使用
MyActivity.this.startService(new Intent(MyActivity.this, MyService.class));
还有更多examples on this question。在以这种方式使用之前,您当然可以create an intent and add extras to it。