我怎样才能让一个Android应用程序按照时间做的东西? [英] How can I make an android application do stuff according to time?

查看:123
本文介绍了我怎样才能让一个Android应用程序按照时间做的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮助我?我无法找到这样做的一个简单的方法。

基本上我希望它在说启动(如:嘿,早上好Mr.xyz)。任何想法?

在此先感谢。

解决方案:

  int类型的= Calendar.getInstance()获得(Calendar.HOUR_OF_DAY)。
        如果(一个或GT; = 4和&放大器;一个与所述; 12){
            messages.add(新的消息(假)早安!);
            说=早安!;}


解决方案

您可以得到最新的一天中的小时,现在做这个:

  Calendar.get(Calendar.HOUR_OF_DAY)

然后使用一些条件检查,你会得出什么结论,你的应用程序有说像早晨,傍晚或下午

和你可以让你的应用程序说任何你已经使用TTS比如像这样的结论:

  = TTS文字转语音新(这一点,这一点);
tts.speak(早安/夜晚/ agternoon,TextToSpeech.QUEUE_FLUSH,NULL);

还你的类必须的实施TextToSpeech.OnInitListener

和你希望你的应用程序应该在一开始迎接用户,你应该写这一切的onCreate()你的第一个活动。

Can anyone help me with this? I'm unable to find a simple way of doing it.

Basically I want it to say at the start up (eg: Hey, Good Morning Mr.xyz). Any ideas?

Thanks in advance.

Solution:

int a = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
        if (a >= 4 && a < 12) {
            messages.add(new Message("Good Morning!",false));
            say = "Good Morning!";}

解决方案

you can get whats the hour of the day right now by doing this:

Calendar.get(Calendar.HOUR_OF_DAY)

and then using some condition checking you will conclude what you application has to say like morning , evening or afternoon

and you can make your app say whatever you have concluded using TTS instance like this:

tts = new TextToSpeech(this, this);
tts.speak("Good Morning/evening/agternoon", TextToSpeech.QUEUE_FLUSH, null);

also your class will have to implement TextToSpeech.OnInitListener

and as you wish your app should greet user at the start you should write all this in onCreate() of your first activity

这篇关于我怎样才能让一个Android应用程序按照时间做的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆