2012-01-24 211 views
0

海想設置報警每10 minutes.But其運行僅第一次任何機構好心幫我如何在Android應用程序中每10分鐘設置一次鬧鐘?

Intent intent = new Intent(this, ConnectionReceiver.class); 

PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, 
intent, PendingIntent.FLAG_ONE_SHOT); 

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (1 * 1000), pendingIntent); 
Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();//every 10 minutes i want to print the toast 
+0

用代碼中的alarmManager替換(1 * 1000)(10 * 60 * 1000)。 – Hiral

回答

2
Calendar calCurrent = Calendar.getInstance(); 
    long tenmin = 10 * 60 * 1000; 
    int mynotifyidis = Integer.parseInt(mydelid); 
    Intent mIntent = new Intent(this, NotificationService1.class); 
    mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    mIntent.putExtra("id", mynotifyidis); 

    AlarmManager mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); 
    PendingIntent snoozependingintent = PendingIntent.getService(this, 
      -mynotifyidis, mIntent, PendingIntent.FLAG_ONE_SHOT); 

    mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 
      calCurrent.getTimeInMillis() + fivemin, fivemin, 
      snoozependingintent);