次のコードを使用しています
AlarmManager service = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(this, AlarmReceiver.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pending = PendingIntent.getBroadcast(this, 0, i,PendingIntent.FLAG_CANCEL_CURRENT);
Calendar cal = Calendar.getInstance();
// Start 30 seconds after boot completed
cal.add(Calendar.SECOND, 30);
//
// Fetch every 30 seconds
// InexactRepeating allows Android to optimize the energy consumption
service.setInexactRepeating(AlarmManager.RTC_WAKEUP ,cal.getTimeInMillis(),AlarmManager.INTERVAL_DAY , pending);
// service.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
// REPEAT_TIME, pending);
私のコードでは、1 日間隔で動作し、AlarmReceiver サービスのブロードキャストを行うことを願っています。
ただし、これはちょうど1か月後に発生することを望んでいます。たとえば、ある人が 1 月 3 日にアプリケーションをインストールすると、次のアラームは 2 月 3 日に発生します。どうすれば1か月の間隔を置くことができますか。