Quiero utilizar la notificación local en Android para mi aplicación. Si la aplicación no se abre durante 24 horas, se envía una notificación local. ¿Alguien me puede decir cómo se debe hacer?Envío de notificaciones locales en Android
Respuesta
Ver: Local Notifications in Android? Debería poder programar una intención con el administrador de alarmas cada hora.
Gracias por la respuesta rápida, pero se puede utilizar el administrador de alarma si la aplicación está cerrada. ¿Cómo se activará la notificación si la aplicación está cerrada? –
Sí, el administrador de alarmas aún se puede usar incluso cuando la aplicación está cerrada. Sin embargo, no podrá configurar un administrador de alarmas cuando la aplicación esté instalada, solo cuando la aplicación esté cargada (al menos una vez) (Ver: http://stackoverflow.com/a/8492846/986105). Eche un vistazo a esto para crear una notificación usando el administrador de alarmas: http://smartandroidians.blogspot.com/2010/04/alarmmanager-and-notification-in.html – KrispyDonuts
Si desea disparar la notificación local con gran decir, los datos, con el texto de varias líneas en una sola notificación con título, Ticker, icono, sonido .. uso siguiente código .. creo que le ayudará a ..
Intent notificationIntent = new Intent(context,
ReminderListActivity.class);
notificationIntent.putExtra("clicked", "Notification Clicked");
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP); // To open only one activity
// Invoking the default notification service
NotificationManager mNotificationManager;
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context);
Uri uri = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
mBuilder.setContentTitle("Reminder");
mBuilder.setContentText("You have new Reminders.");
mBuilder.setTicker("New Reminder Alert!");
mBuilder.setSmallIcon(R.drawable.clock);
mBuilder.setSound(uri);
mBuilder.setAutoCancel(true);
// Add Big View Specific Configuration
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
String[] events = null;
events[0] = new String("Your first line text ");
events[1] = new String(" Your second line text");
// Sets a title for the Inbox style big view
inboxStyle.setBigContentTitle("You have Reminders:");
// Moves events into the big view
for (int i = 0; i < events.length; i++) {
inboxStyle.addLine(events[i]);
}
mBuilder.setStyle(inboxStyle);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(context,
ReminderListActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder
.create(context);
stackBuilder.addParentStack(ReminderListActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder
.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
// notificationID allows you to update the notification later on.
mNotificationManager.notify(999, mBuilder.build());
Intent intent = new Intent(context, yourActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder b = new NotificationCompat.Builder(context);
b.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_launcher)
.setTicker("notification")
.setContentTitle("notification")
.setContentText("notification")
.setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND)
.setContentIntent(pIntent)
.setContentInfo("Info");
NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, b.build());
- 1. iPhone: notificaciones locales diarias
- 2. Envío de notificaciones con GObjects
- 3. Alarma de iPhone usando notificaciones locales repetidas
- 4. Borrar insignia de aplicación con notificaciones locales
- 5. Escuchando notificaciones en Android
- 6. ¿Cómo configurar notificaciones locales en Mac OS X?
- 7. cómo crear notificaciones locales en la aplicación iphone
- 8. ¿Cómo hacer notificaciones en android?
- 9. Notificaciones repetitivas en Android 4
- 10. ¿Reproduce el sonido predeterminado de notificaciones locales al mostrar UIAlertView?
- 11. Android: administración de múltiples notificaciones
- 12. Recibe notificaciones actuales de Android
- 13. Datos principales: observe los cambios y registre las notificaciones locales
- 14. Mostrar notificaciones de Android cada cinco minutos
- 15. iphone y notificaciones: ¿número máximo de notificaciones?
- 16. Android: las notificaciones automáticas GCM no aparecen en la lista de notificaciones
- 17. Android: Administración de notificaciones múltiples en la barra de estado
- 18. notificaciones de GCM en android 3.1: deshabilitar receptor de difusión
- 19. de notificaciones de Android con botones en él
- 20. Ocultar barra de notificaciones
- 21. notificaciones Push para Android y iPhone
- 22. Android: reciba todas las notificaciones por código
- 23. Android problema de envío de archivo Bluetooth
- 24. iniciar una aplicación desde la barra de notificaciones en android
- 25. ¿Es posible mostrar notificaciones locales mientras la aplicación iphone está en pantalla?
- 26. ¿Cuál es una buena forma de administrar las notificaciones locales que ha programado su aplicación?
- 27. Envío de datos SMS en Android en un teléfono CDMA
- 28. Eliminar notificaciones de la barra de notificaciones de otras aplicaciones
- 29. Aplicación en el mercado Android: las notificaciones HTTP no vienen
- 30. Notificaciones push en Android: Google GCM vs. Amazon SNS?
¿por qué no u utilizar una alarma de – Zamani
Creo que se debe crear de servicio y luego comprobar el tiempo, pero para mostrar la notificación u debe leer sobre él. =) – Gorets
Gorets, tiene toda la razón, tengo que utilizar algún tipo de servicio ya que la notificación se activará cuando se cierre la aplicación. ¿Me puede dar algún tutorial para que –