我想在我的 android 应用程序打开时提供音频消息,就像“欢迎我们的系统”一样,但我不能。
代码:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String text="Welcome to our location based system";
if (text!=null && text.length()>0)
{
Toast.makeText(SimpleAudioTestActivity.this, "Saying: " + text, Toast.LENGTH_LONG).show();
tts.speak(text, TextToSpeech.QUEUE_ADD, null);
}
Intent checkintent=new Intent();
checkintent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkintent, MY_DATA_CHECK_CODE);
}
当我单击按钮后执行此操作时,就可以了:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
but1=(Button) findViewById(R.id.button1);
but1.setonclickListener(new View.onclickListener()
{
@Override
public void onclick(View arg0)
{
String text="Welcome to our location based system";
if (text!=null && text.length()>0)
{
Toast.makeText(SimpleAudioTestActivity.this, "Saying: " + text, Toast.LENGTH_LONG).show();
tts.speak(text, TextToSpeech.QUEUE_ADD, null);
}
}
});
Intent checkintent=new Intent();
checkintent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkintent, MY_DATA_CHECK_CODE);
}
我怎样才能做到这一点?请有任何建议。