我已经尝试过此代码在三月首先发出警报。但它不起作用。我怎么解决这个问题?
APP内容
当我们按下按钮(click1)时,如果是三月一号,Alarmmanger 会调用 Intent。所以这个应用程序打印新的活动。
错误
当我们按下按钮(click1)时,任何时候Alarmmanger都会调用intent。
我该如何解决?
-对不起我的英语不好..ㅠㅠ
public class MainActivity extends Activity {
private AlarmManager alarm;
private NotificationManager notification;
Calendar calendar = Calendar.getInstance();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);}
public void click1(View v) {
notification = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(System.currentTimeMillis());
calendar.clear();
calendar.set(cal.YEAR,3,1);
setAlarm();
}
private void setAlarm(){
alarm.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent());
}
private PendingIntent pendingIntent() {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent p = PendingIntent.getActivity(this, 0, i, 0);
return p;
}