-1
我試圖改變AlarmManager的時間爲1天,3天和7天點擊相應的按鈕。例如,如果我點擊「1天」按鈕,鬧鐘應該設置爲每天重複的方式等等。但我不知道如何實現這一點,我有預先定義的時間重複報警的代碼設置AlarmManager時間onClick android
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(this, NotifyService.class);
PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager) this
.getSystemService(Context.ALARM_SERVICE);
long recurring = (1 * 60000 * 60 * 24); // repeat every 24 hrs
am.setRepeating(AlarmManager.RTC, Calendar.getInstance()
.getTimeInMillis(), recurring, sender);
}
public void set1day(View view) {
//...
}
public void set3days(View view) {
//...
}
public void set7days(View view) {
//...
}
}