2011-11-26 7 views
9

मैं अपनी अधिसूचना प्रतिदिन 12:00 बजे चलाने के लिए चाहूंगा। एक समय के साथ मूल्य को आप कैसे बदलते हैं?विशिष्ट समय पर अधिसूचना सेट करें

NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
Notification notify = new Notification(R.drawable.icon,"Its Time to Eat",when); 

Context context = GrubNOWActivity.this; 
CharSequence title = "Its Time to Eat"; 
CharSequence details = "Click Here to Search for Restaurants"; 
Intent intent = new Intent(context,Search.class); 
PendingIntent pending = PendingIntent.getActivity(context, 0, intent, 0); 
notify.setLatestEventInfo(context, title, details, pending); 
nm.notify(0,notify); 

उत्तर

41

आप एक अलार्म प्रबंधक

Intent myIntent = new Intent(ThisApp.this , myService.class);  
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); 
pendingIntent = PendingIntent.getService(ThisApp.this, 0, myIntent, 0); 

Calendar calendar = Calendar.getInstance(); 
calendar.set(Calendar.HOUR_OF_DAY, 12); 
calendar.set(Calendar.MINUTE, 00); 
calendar.set(Calendar.SECOND, 00); 

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24*60*60*1000 , pendingIntent); //set repeating every 24 hours 

का उपयोग करें और MyService वर्ग के भीतर अधिसूचना डाल कर सकते हैं!

+0

ऐसा लगता है कि ऐसा हुआ है, धन्यवाद! –

+0

लेकिन किसी एक विशेष समय के लिए इसे कैसे सेट करें? मान लीजिए कि मैं इसे सेट करना चाहता हूं जब यह 10 पीएम है मैं यह कैसे करूँ? – silverFoxA

+0

इसे विशिष्ट दिन के लिए केवल सोमवार से शुक्रवार के लिए कैसे सेट करें और यह समय 12 बजे है? –

1

when पैरामीटर स्टेटस बार में अधिसूचनाओं को क्रमबद्ध करने के लिए है। आपको अपने ऐप को कोड करना चाहिए ताकि वह वांछित समय पर अधिसूचना को सक्रिय कर सके।