我使用以下代码在每个星期一上午8:45触发警报。
Calendar cl1 = Calendar.getInstance();
cl1.set(Calendar.DAY_OF_WEEK, 2);
cl1.set(Calendar.HOUR, 8);
cl1.set(Calendar.MINUTE, 45);
cl1.set(Calendar.SECOND, 0);
long tme = cl1.getTimeInMillis();
Intent intent = newIntent(Mondayentry.this,Alarmreceiver.class);
PendingIntent pendingintent = PendingIntent.getBroadcast(Mondayentry.this,0,intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager al = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
al.setRepeating(AlarmManager.RTC_WAKEUP, tme,7*1440*60000, pendingintent);
我使用了以下广播类
public class Alarmreceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Alarm generated", Toast.LENGTH_SHORT).show();
}
}
我还在清单文件中添加了
<receiver android:name=".Alarmreceiver"> </receiver>
没有错误,但根本没有触发警报。 请帮帮我。