// MainActivity 소스이고
public class MainActivity extends Activity implements TextToSpeech.OnInitListener {
public TextView textView;
public TextToSpeech tts;
@Override
public void onInit(int status){
if(status== TextToSpeech.SUCCESS){
tts.setLanguage(Locale.KOREAN);//한국말 설정
tts.setPitch(0.5f);
tts.setSpeechRate(1.0f);
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView)findViewById(R.id.textView);
String str = ("아리리리");
textView.setText(str);
Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent, 0);
// 알람을 받을 시간을 5초 뒤로 설정
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 2);
// 알람 매니저에 알람을 등록
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
}
public String test() {
return textView.getText().toString();
}
}
//알람매니저 소스입니다
public class AlarmReceiver extends BroadcastReceiver implements TextToSpeech.OnInitListener {
public MainActivity mainActivity;
public TextToSpeech tts;
public AlarmReceiver AlarmReceiver;
@Override
public void onInit(int status){
if(status== TextToSpeech.SUCCESS){
tts.setLanguage(Locale.KOREAN);//한국말 설정
tts.setPitch(0.5f);
tts.setSpeechRate(1.0f);
}
}
/* public void setAlarm()
{
alarmReceiver = new AlarmReceiver();
}*/
public void AlarmReceiver(MainActivity ma) {
mainActivity=ma;
tts = new TextToSpeech(mainActivity, this);
}
@Override
public void onReceive(Context context, Intent intent) {
// alarmReceiver.setAlarm();
String str=mainActivity.test();
Toast.makeText(context,"알람",Toast.LENGTH_SHORT).show();
tts.speak(str,TextToSpeech.QUEUE_FLUSH, null, null);
}
알람매니저를 통해서 2초뒤에 TTS가 나오도록 하는 소스인데 2초뒤에
어플이 중지되었다고 뜨네요
onReceive 함수에서 toast 메세지 구문만 넣으면 오류가없이
2초뒤에 토스트메세지가 뜨는데 TTS를 넣으려니 자꾸 어플이 중지되었다고 뜨네요 ㅠㅠ 소스를 어떻게 수정해야하나요?ㅠㅠ