android alarm相关信息

1. Action定义:

public static final String ALARM_SNOOZE_ACTION = "com.android.deskclock.ALARM_SNOOZE";
	public static final String ALARM_DISMISS_ACTION = "com.android.deskclock.ALARM_DISMISS";
	public static final String ALARM_DONE_ACTION = "com.android.deskclock.ALARM_DONE";
	public static final String ALARM_ALERT_ACTION = "com.android.deskclock.ALARM_ALERT";

 

2.注册闹钟广播:

private void registerAlarm() {
		IntentFilter filter = new IntentFilter();
		filter.addAction("com.android.deskclock.ALARM_ALERT");
		filter.addAction("com.android.deskclock.ALARM_DONE");
		filter.addAction("com.android.deskclock.ALARM_DISMISS");
		filter.addAction("com.android.deskclock.ALARM_SNOOZE");
		registerReceiver(mReceiver, filter);
	}

	private BroadcastReceiver mReceiver = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, Intent intent) {
			String action = intent.getAction();
			Log.i("Tag", "AlarmActivity - Broadcast Receiver - " + action);
			if (action.equals(ALARM_SNOOZE_ACTION)) {
				// snooze();
			} else if (action.equals(ALARM_DISMISS_ACTION)) {
				// dismiss();
			} else if (action.equals("com.android.deskclock.ALARM_ALERT")) {
				new Thread(waitStopAlarm).start();
			} else {
				Log.i("Tag", "Unknown broadcast in AlarmActivity: " + action);
			}
		}
	};

 

private Runnable waitStopAlarm = new Runnable() {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			try {
				Thread.sleep(2000);
			} catch (Exception e) {
				// TODO: handle exception
			}
			stopAlarm();
		}
	};

	private void stopAlarm() {
		Log.i("Tag", "stop alarm");
		Intent intent = new Intent();
		intent.setAction("com.android.deskclock.ALARM_DISMISS");
		sendBroadcast(intent);
	}

	private void snoozeAlarm() {
		Intent intent = new Intent();
		intent.setAction("com.android.deskclock.ALARM_SNOOZE");
		sendBroadcast(intent);
	}

 

3.新增加闹钟:

Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
		intent.putExtra(AlarmClock.EXTRA_MESSAGE, "New Alarm!");
		intent.putExtra(AlarmClock.EXTRA_HOUR, hour);
		intent.putExtra(AlarmClock.EXTRA_MINUTES, minutes);
		intent.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
		startActivity(intent);

 

4.权限:

<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />

 

详细信息请移步:http://blog.csdn.net/yihongyuelan

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值