Android 编辑文本以设置重复报警
我试图设置一个警报,在几分钟内重复编辑文本,但它似乎只是工作时,它想Android 编辑文本以设置重复报警,android,android-edittext,alarmmanager,Android,Android Edittext,Alarmmanager,我试图设置一个警报,在几分钟内重复编辑文本,但它似乎只是工作时,它想 public void startAlert(View view) { EditText text = (EditText) findViewById(R.id.time); int i = Integer.parseInt(text.getText().toString()); try { Intent myIntent = new Intent(thi
public void startAlert(View view) {
EditText text = (EditText) findViewById(R.id.time);
int i = Integer.parseInt(text.getText().toString());
try {
Intent myIntent = new Intent(this, NotifyService.class);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
pendingintrent = PendingIntent.getService(this.getApplicationContext(),
12345, myIntent, 0);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(),
i * 60 * 60 , pendingintrent);
} catch (Exception e) {}
Toast.makeText(this, "Alarm set in " + i + " minutes",
Toast.LENGTH_LONG).show();
finish();
}
}
setRepeating()
方法中的时间间隔值为毫秒格式。因此,您需要更改setRepeating()
方法的行,如下所示
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(),
i * 60 * 60 * 1000, pendingintrent);