2012-01-30 12 views
5

Quiero configurar mi notificación en android en una fecha y hora determinada, la intento utilizando la fecha en java, pero mi notificación se activa antes de tiempo. Entonces, ¿qué puedo hacer para que se active en el tiempo especificado? ¡Gracias por adelantado!¿Cómo iniciar la notificación en el momento personalizado?

Aquí está mi código de notificación:

Calendar cal = java.util.Calendar.getInstance(); 
cal.set(2012, 00, 30); 
Date date = cal.getTime(); 
date.setHours(17); 
date.setMinutes(30); 
date.setSeconds(15); 

long time = date.getTime(); 

Log.e("date is",""+date); 
long when = time; 


Notification notification = new Notification(notificationIcon,tickerText,date.getTime()); 

notification.when = date.getTime(); 

RemoteViews contentView = new RemoteViews("com.LayoutDemo",R.layout.userscreen);   
notification.contentView= contentView; 
Intent intent = this.getIntent(); 
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0); 
notification.contentIntent= contentIntent; 

notification.flags= Notification.FLAG_AUTO_CANCEL; 

int NOTIFICATION_ID =1;    
nManager.notify(NOTIFICATION_ID,notification); 
+0

Ok gracias !! ¿Tiene alguna idea sobre cómo iniciar el servicio para sembrar la notificación? –

Respuesta

2

uso de alarma Android y en esa pendiente de establecer la intención

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