编辑文本以设置重复警报

时间:2014-04-28 03:15:52

标签: 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(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();
    }
}

1 个答案:

答案 0 :(得分:0)

setRepeating()方法中的时间间隔值以毫秒格式表示。因此,您需要更改setRepeating()方法的行,如下所示

alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(),
        i * 60 * 60 * 1000, pendingintrent);