2014-04-28 166 views
0

我想設置一個報警,在幾分鐘內重複編輯文本,但它似乎只是當它想要工作。編輯文本設置重複報警

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

回答

0

setRepeating()方法的時間間隔值是在毫秒的格式。所以你需要改變你的setRepeating()方法的線如下,

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