android设置闹钟日期,具有特定日期的Android闹钟设置

我想在特定日期通知通知.然后我现在正在使用带有NotificationManager的AmarmManager.当我从dateDialog设置所选日期时,警报正在运行.如何在固定时间内将日历值设置在闹钟设置上?我希望每天在固定时间重复闹钟,例如早上9点.目前,警报忽略了特定日期的时间.你可以帮帮我吗?非常感谢.

confirmButton.setOnClickListener(new View.OnClickListener()

{

public void onClick(View v) {

//set alarm with expiration date

am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

setOneTimeAlarm();

Toast.makeText(fridgeDetails.this, "Alarm automatic set", Toast.LENGTH_SHORT).show();

setResult(RESULT_OK);

finish();

}

public void setOneTimeAlarm() {

c.set(Calendar.HOUR_OF_DAY, 10);

c.set(Calendar.MINUTE, 0);

c.set(expiredYear, expiredMonth, expiredDay);

Intent myIntent = new Intent(fridgeDetails.this, AlarmService.class);

PendingIntent pendingIntent = PendingIntent.getBroadcast(fridgeDetails.this,

0, myIntent, PendingIntent.FLAG_ONE_SHOT);

am.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pendingIntent);

}

});

private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener()

{

public void onDateSet(DatePicker view, int year, int monthOfYear,

int dayOfMonth) {

expiredYear = year;

expiredMonth = monthOfYear;

expiredDay = dayOfMonth;

displayDate();

}

};

public class AlarmService extends BroadcastReceiver{

NotificationManager nm;

@Override

public void onReceive(Context context, Intent intent) {

nm = (NotificationManager) context

.getSystemService(Context.NOTIFICATION_SERVICE);

CharSequence from = "Check your fridge";

CharSequence message = "It's time to eat!";

PendingIntent contentIntent = PendingIntent.getActivity(context, 0,

new Intent(), 0);

Notification notif = new Notification(R.drawable.ic_launcher,

"Keep Fridge", System.currentTimeMillis());

notif.setLatestEventInfo(context, from, message, contentIntent);

nm.notify(1, notif);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值