Notificaciones locales en Android?

Puedo enviar notificaciones locales en Android, como puedo en el iPhone?

Utilice NotificationCompat.Builder si también está apuntando APIs antiguas.

Intent intent = new Intent(ctx, HomeActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder b = new NotificationCompat.Builder(ctx); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.ic_launcher) .setTicker("Hearty365") .setContentTitle("Default notification") .setContentText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.") .setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND) .setContentIntent(contentIntent) .setContentInfo("Info"); NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(1, b.build()); 

LocalBroadcastManager se parece a una mejor solución: http://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager.html Crea tu propia acción de intención personalizada, transmítela a tu proceso y asegúrate de cualquier actividad, etc. Está registrado como un receptor para esa intención.

Enviar una notificación local al usuario en Android es bastante simple. Hacemos uso de NotificationManager, un Intent y un PendingIntent.

 public void notifyUser() { NotificationManager notificationManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE); Intent intent = new Intent(MyActivity.this, SomeActivity.class); //use the flag FLAG_UPDATE_CURRENT to override any notification already there PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new Notification(R.drawable.ic_launcher, "Some Text", System.currentTimeMillis()); notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND; notification.setLatestEventInfo(this, "This is a notification Title", "Notification Text", contentIntent); //10 is a random number I chose to act as the id for this notification notificationManager.notify(10, notification); } 

Si desea activar la notificación local con datos grandes es decir, con texto multilínea en una sola notificación con título, Ticker, icono, sonido .. use el siguiente código .. Creo que le ayudará ..

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

Para entender cómo funciona la notificación local en android vaya a esta pregunta – ¿Cómo programar las notificaciones locales de Android?

  • El proceso de fondo de la aplicación se detiene, si el dispositivo se ha iniciado
  • Ocultar la barra de progreso del área de notificación en android cuando se completa el 100%
  • Vista personalizada con clics en Notificación en Android 2.3 o inferior
  • Configuración de un icono de notificación de Android en una URL remota
  • Java Android - Redmi 3 (MIUI) - No se pueden cambiar los iconos de notificación?
  • Android: icono de notificación de la barra de estado incremental
  • ¿Cómo puedo crear una notificación en la barra de estado de android?
  • Cómo deshabilitar la barra de estado o barra de notificación, pero no deshabilitar la barra de título en android?
  • ¿Cómo enviar notificaciones a usuarios específicos con FCM?
  • ¿Qué significa gcm.notification.e = 1, en la carga de notificación push en Android?
  • Import android.support no se puede resolver
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.