我正在创建一个应用程序,让用户可以选择日期并在当天的特定时间开始闹钟。
让我的问题作为一个例子我希望我的闹钟每周五12:30开火 问题是,即使我在同一天这里是我的代码,它也永远不会发出警报
cals = Calendar.getInstance();
int days = Calendar.FRIDAY + (7 - cals.get(Calendar.DAY_OF_WEEK)); // how many days until Sunday
cals.add(Calendar.DATE, days);
cals.set(Calendar.DAY_OF_WEEK,6);
cals.set(Calendar.HOUR_OF_DAY, 12);
cals.set(Calendar.MINUTE, 30);
cals.set(Calendar.SECOND, 0);
cals.set(Calendar.MILLISECOND, 0);
alarm.SetAlarm(getApplicationContext(), 10,"Start", cals.getTimeInMillis());
public void SetAlarm(Context context,int id,String sor,long time)
{
AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
if(sor.equals("Start"))
{
Intent i = new Intent(context, MyAppReceiver.class);
PendingIntent p = PendingIntent.getBroadcast(context, 0, i, 0);
am.setRepeating(AlarmManager.RTC_WAKEUP, time, DateUtils.DAY_IN_MILLIS, p);
}
}
答案 0 :(得分:1)
您是否在AndroidManifest.xml中将 MyAppReceiver 注册为BroadcastReceiver?