2010-12-30 15 views
22

मैं एक अनुसूची बनाने की कोशिश कर रहा हूं।अलार्ममेनर एंड्रॉइड हर दिन

यह 1:00 या 2 बजे हर दिन चलाना चाहिए ...

पल मैं केवल यह हर 10sec या 10min चलाने कर सकते हैं पर ...

Intent myIntent = new Intent(AndroidAlarmService.this, MyAlarmService.class); 
pendingIntent = PendingIntent.getService(AndroidAlarmService.this, 0, myIntent, 0); 

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 

Calendar calendar = Calendar.getInstance(); 
calendar.setTimeInMillis(System.currentTimeMillis()); 
calendar.add(Calendar.SECOND, 10); 
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); 

Toast.makeText(AndroidAlarmService.this, "Start Alarm", Toast.LENGTH_LONG).show(); 

धन्यवाद

उत्तर

-10

हो जाएगा ताकि अलार्म हर दिन।

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, AlarmManager.INTERVAL_DAY , pendingIntent); 
+5

'सेट()' केवल एक बार सक्रिय होगा। 'सेट दोहराना() 'हर दिन आग लग जाएगा। – CommonsWare

+0

आपको धन्यवाद और गलतफहमी के लिए खेद है। –

+0

-1 यह कोड सही नहीं है (कम से कम एसडीके 2.1 के रूप में)। AlarmManager.setRepeating 4 मानकों को स्वीकार करता है, नहीं 3. – Valentin

89

यह कोड 1 प्रधानमंत्री से प्रत्येक दिन आशय चलेंगे या 2 PM पर

Calendar calendar = Calendar.getInstance(); 

calendar.set(Calendar.HOUR_OF_DAY, 13); // For 1 PM or 2 PM 
calendar.set(Calendar.MINUTE, 0); 
calendar.set(Calendar.SECOND, 0); 
PendingIntent pi = PendingIntent.getService(context, 0, 
      new Intent(context, MyClass.class),PendingIntent.FLAG_UPDATE_CURRENT); 
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 
           AlarmManager.INTERVAL_DAY, pi); 
+21

आप कैलेंडर.add (कैलेंडर। DAY_OF_YEAR, 1) जोड़ना चाहते हैं; तुरंत अलार्म फायरिंग से बचने के लिए। – ben

+0

आप कैलेंडर.सेट भी जोड़ सकते हैं (कैलेंडर.मिलीसेकोन्ड, 0); अधिक सटीक होने के लिए :) – JDJ

+1

क्या यह भी तब चलता है जब एप्लिकेशन पृष्ठभूमि/बंद/रोका जाता है? –

संबंधित मुद्दे