调用系统时间dialog(TimePicker),并设置定时提醒功能

/**
	 * 顯示時間選擇dialog
	 */
	private void showTimePickerDialog() {
		Calendar calendar = Calendar.getInstance();
		int hour=calendar.get(Calendar.HOUR_OF_DAY);
		int minute = calendar.get(Calendar.MINUTE);

		final TimePickerDialog timePickerDialog = new TimePickerDialog(mContext,setting,hour,minute,true);
		timePickerDialog.setIcon(R.drawable.ic_launcher);
		timePickerDialog.show();

	}
</pre><pre code_snippet_id="599288" snippet_file_name="blog_20150206_3_6899549" name="code" class="java">//当点击TimePickerDialog控件的设置按钮时,调用该方法    
	TimePickerDialog.OnTimeSetListener setting = new TimePickerDialog.OnTimeSetListener(){
		@Override
		public void onTimeSet(TimePicker view, int hour, int minute){

			Intent intent = new Intent(mContext, AlarmReceiver.class);
			PendingIntent sender = PendingIntent.getBroadcast(mContext, 0, intent, 0);
	        long systemTime = System.currentTimeMillis();
	        Calendar calendar = Calendar.getInstance();
		 	calendar.setTimeInMillis(System.currentTimeMillis());
		 	calendar.setTimeZone(TimeZone.getTimeZone("GMT+8")); // 这里时区需要设置一下,不然会有8个小时的时间差
		 	calendar.set(Calendar.MINUTE, minute);
		 	calendar.set(Calendar.HOUR_OF_DAY, hour);
		 	calendar.set(Calendar.SECOND, 0);
		 	calendar.set(Calendar.MILLISECOND, 0);

		 	SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm");
			String timeStr = sdfTime.format(calendar.getTime())+"";
			remind_time_text.setText(timeStr);//设置显示文字 如:20:08
			SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
			Date currentDate = new Date();
		 	// 选择的每天定时时间
		 	long selectTime = calendar.getTimeInMillis();	

		 	//保存设置提醒的日期
		 	SharedPreferences.setOpenAppDate(mContext, sdfDate.format(currentDate));
	        // 进行闹铃注册,设置每天的提醒时间
	        AlarmManager manager = (AlarmManager)getSystemService(ALARM_SERVICE);
	        manager.setRepeating(AlarmManager.RTC_WAKEUP, selectTime, 24*60*60*1000, sender);
	        Toast.makeText(mContext, "设置成功! ", Toast.LENGTH_LONG).show();
		}
    };
//接收闹铃提醒时的广播
public class AlarmReceiver extends BroadcastReceiver {
	public void onReceive(Context context, Intent intent) {
<span style="white-space:pre">		</span>Log.e("AlarmReceiver","闹铃响了, 可以做点事情了~~");
</pre><pre code_snippet_id="599288" snippet_file_name="blog_20150206_9_199033" name="code" class="java"><span style="white-space:pre">	</span>}
</pre><pre code_snippet_id="599288" snippet_file_name="blog_20150206_11_7718869" name="code" class="java">}

清单文件中加入

 <receiver android:name="com.xxxx.android.AlarmReceiver" android:process=":remote">
         


时间: 2024-08-24 14:08:31

调用系统时间dialog(TimePicker),并设置定时提醒功能的相关文章

jsp页面中,动态调用系统时间的实现

在做WEB项目时,常常会需要 在页面中显示当前时间,下面介绍一个简单的调用系统时间的方法,效果如图: 在页面中插入下面代码就行了 <div id="time"> 当前时间: <script> document.getElementById('time').innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay()); setInterval("docu

巧用Windows 7计划任务设置定时提醒

Windows 7系统有个“计划任务”功能,一般人都很少使用.其实,“计划任务”是系统自带的一个很实用的功能,比如说,这个功能可以设置定时提醒,这样在使用电脑时就不会因为太过投入而导致错过重要的事务.下面,小编就介绍一下这个“计划任务”功能的具体使用方法. 工具/原料 Windows 7计划任务 方法/步骤 1 单击开始菜单,在最下方的搜索框里搜索“计划任务”,再单击打开“任务计划程序”. 2 在“任务计划程序”窗口单击“创建基本任务”,打开“创建基本任务向导”.   输入任务的“名称”以及“描

标准IO的简单应用,动静态库,读取系统时间并打印,模拟ls -l功能

2015.2.27星期五,小雨 标准IO实现的复制功能: #include <stdio.h>#include <errno.h> #define N 64 int main(int argc, char *argv[]){ int n; char buf[N]; FILE *fps, *fpd; if(argc < 3) { printf("usage : %s <src_file><dst_file>\n",argv[0]);

Android 每天定时提醒功能实现

android要实现定时的功能那肯定就要用到闹铃相关的技术, 那么android闹铃实现是基于 AlarmManager 这个类的,首先我们来看一下它的几个主要的方法. 打开AlarmManager的源码,如下图显示: 两个核心的方法 : private final IAlarmManager mService; public void set(int type, long triggerAtMillis, PendingIntent operation) { try { mService.se

CentOS7 使用ntp设置系统时间,开机自动设置时间,

首先如果没有安装ntp自己装一下: yum install -y ntp 然后,如果开了防火墙,记得打开自己的123端口,该端口是ntp用来同步时间的 firewall-cmd --zone=public --add-port=123/udp --permanent firewall-cmd --reload 然后配置ntp: vi /etc/ntp.conf 将原来的server都注掉: 如果自己是时间服务器服务端,那么添加内容如下: server 127.127.1.0 fudge 127.

调用系统时间

VS中编译通过: #include<stdio.h> #include<stdlib.h> #include<time.h> int main() { printf("This is a test!\n"); time_t rawtime; rawtime = time(NULL); struct tm *systime = localtime(&rawtime); printf("Time is: %s", asctim

Winform调用系统的剪切,复制,粘贴文件功能

// <summary> /// 复制或剪切文件至剪贴板(方法) /// </summary> /// <param name="files">需要添加到剪切板的文件路径数组</param> /// <param name="cut">是否剪切true为剪切,false为复制</param> public static void CopyToClipboard(string[] files, b

Linux的系统时间和硬件时间

一.概念: Linux系统中时间分为系统时间和硬件时间: 系统时间是指Linux内核中的时间; 硬件时间是指主板上的硬件时钟所计算的时间.不同的时间,设置的方法也不一样. 详细说明如下: 1. "系统时间"与"硬件时间" 系统时间: 一般说来就是我们执行 date 命令看到的时间,linux系统下所有的时间调用(除了直接访问硬件时间的命令)都是使用的这个时间. 硬件时间: 主板上BIOS中的时间,由主板电池供电来维持运行,系统开机时要读取这个时间,并根据它来设定系统

LINUX下系统时间

Linux时钟分为系统时钟(System Clock)和硬件(Real Time Clock,简称RTC)时钟.系统时钟是指当前Linux Kernel中的时钟,而硬件时钟则是主板上由电池供电的时钟,这个硬件时钟可以在BIOS中进行设置.当Linux启动时,硬件时钟会去读取系统时钟的设置,然后系统时钟就会独立于硬件运作. Linux中的所有命令(包括函数)都是采用的系统时钟设置.在Linux中,用于时钟查看和设置的命令主要有date.hwclock和clock.其 中,clock和hwclock