2011-11-26 20 views
9

Me gustaría que mi notificación se ejecute a las 12:00 pm todos los días. ¿Cómo se reemplaza el valor cuando con un tiempo?Establecer la notificación a la hora específica

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

Respuesta

41

Se puede utilizar un gestor de alarma

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 

y poner la notificación dentro de la clase myService!

+0

que parece haberlo hecho, ¡gracias! –

+0

, pero ¿cómo se puede configurar para un tiempo en particular? digamos que quiero que se establezca cuando son 10Pm, ¿cómo hago eso? – silverFoxA

+0

cómo configurarlo para un día específico, por ejemplo, de lunes a viernes y es hora de las 12 pm? –

1

El parámetro when es para la clasificación de las notificaciones en la barra de estado. Debe codificar su aplicación para que active la notificación en el momento deseado.

Cuestiones relacionadas