package com.itheima.hoc;
import static com.google.android.material.snackbar.BaseTransientBottomBar.handler;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.speech.tts.TextToSpeech;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Locale;
public class main extends AppCompatActivity {
Button b10 = findViewById(R.id.b10);
;
private TextToSpeech tts;
public Integer flag = 0;
Handler S = new Handler();
Message message = new Message();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
b10.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Thread(){
@Override
public void run() {
Message message = new Message();
message.what =11;
}
}.start();
}
});
}
public class Tdd implements Runnable{
public void sendMessage(Message message) {
Message message1=Message.obtain()
}
@Override
public void run() {
Handler handler = new Handler() {
//接收处理子线程handler准备好的消息
public void handleMessage(Message msg) {
super.handleMessage(msg);
while (msg.what == 11) {
try {
Thread.sleep(10000);
tts = new TextToSpeech(main.this, new TextToSpeech.OnInitListener() {//实例化自带语音对象
@Override
public void onInit(int i) {
if (i == TextToSpeech.SUCCESS) {//设置语音
tts.setLanguage(Locale.CHINESE);//中文
tts.speak("好", TextToSpeech.QUEUE_FLUSH, null);//播报“今天温度36.3℃”
}
}
});
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
}
}
}
我需要一个每隔10秒响一次的安卓软件