AlarmClock的入门 - 机器人 [英] AlarmClock for Beginners - Android

查看:173
本文介绍了AlarmClock的入门 - 机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是很新的Andr​​oid的,但已经具备Java本身的一些经验。现在我想建立一个要求的时间和日期,然后设置一个闹钟的应用程序。 我已经看了看,通过谷歌的API和很多其他的东西,但要么我不明白,或者它已经过时了。

I'm quite new to Android but already have some experience with Java itself. Now I'd like to set up an App that asks for time and date and then sets up an alarm clock. I already looked through the google apis and lots of other stuff, but either I don't understand it or it's outdated.

谁能帮我设置一个闹钟同时解释它是如何工作?

Can anyone help me to set up that alarm clock while explaining how it works?

感谢:)

推荐答案

这是工作code在10版本需要建立一个意图开始AlarmClock的一个新的实例。确保常数EXTRA_HOUR和EXTRA_MINUTE分配给自己的变量名或硬codeD常数。在这个例子中,他们是codeD从日历(位于java.util.Calendar中)采取了用户输入的时间。

This is working code in version 10. You need to set up an intent to start a new instance of the AlarmClock. make sure to assign the constants EXTRA_HOUR and EXTRA_MINUTE to your own variables names or hard coded constants. In this example they are coded to user entered time taken from the Calendar (located in the java.util.Calendar).

Intent openNewAlarm = new Intent(AlarmClock.ACTION_SET_ALARM);
        openNewAlarm.putExtra(AlarmClock.EXTRA_HOUR, hour_alarm);
        openNewAlarm.putExtra(AlarmClock.EXTRA_MINUTES, minute_alarm);
        startActivity(openNewAlarm);

这下一节获得来自内部时钟的当前时间和返回它在 TimePicker 在这里,用户可以在下一个输入新的时间,它返回意图,设置一个新的警报。

this next section obtains the current time from the internal clock and returns it in a TimePicker Here the user can next enter a new time and return it to the Intent to set a new alarm.

public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the current time as the default values for the picker

        final Calendar c = Calendar.getInstance();
        hour_local = c.get(Calendar.HOUR_OF_DAY);
        minute_local = c.get(Calendar.MINUTE);

        // Create a new instance of TimePickerDialog and return it
        return new TimePickerDialog(getActivity(), this, hour_local, minute_local,
                DateFormat.is24HourFormat(getActivity()));
    } 

要使用的 TimePicker 创建一个内部静态类,一个是调用它里面的活性。看看这个<一href="http://developer.android.com/reference/android/widget/TimePicker.html">http://developer.android.com/reference/android/widget/TimePicker.html

To use a TimePicker create an inner static class, one that is inside of the Activity the calls it. Look at this http://developer.android.com/reference/android/widget/TimePicker.html

这篇关于AlarmClock的入门 - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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