Mostrar texto de notificación en la barra de estado – Android

En mi aplicación necesito mostrar la notificación al usuario. El fragmento de código siguiente funcionó bien al mostrar el icono y el título del contenido en la barra de título del dispositivo Android.

var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager; var uiIntent = new Intent(this, typeof(MainActivity)); var notification = new Notification(Resource.Drawable.AppIcon, title); notification.Flags = NotificationFlags.AutoCancel; notification.SetLatestEventInfo(this, title, desc, PendingIntent.GetActivity(this, 0, uiIntent, 0)); notificationManager.Notify(1, notification); 

Cuando intenté construir el paquete para desplegar la aplicación, consigo el error siguiente:

Android.App.Notification.SetLatestEventInfo (Android.Content.Context, cadena, cadena, Android.App.PendingIntent) 'está obsoleto:' desaprobado '

Así que encontré este fragmento de código que debería usar y muestra el icono en la barra de estado por no el título del contenido

 Intent resultIntent = new Intent(this, typeof(MainActivity)); PendingIntent pi = PendingIntent.GetActivity(this, 0, resultIntent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(Forms.Context) .SetContentIntent(pi) .SetAutoCancel(true) .SetContentTitle(title) .SetSmallIcon(Resource.Drawable.AppIcon) .SetContentText(desc); //This is the icon to display NotificationManager nm = GetSystemService(Context.NotificationService) as NotificationManager; nm.Notify(_TipOfTheDayNotificationId, builder.Build()); 

¿Qué necesito para establecer el nuevo fragmento de código para mostrar el título del contenido en la barra de estado del dispositivo Android?

Necesito agregar .setTicker() al segundo fragmento de código para que se muestre el texto en la barra de estado del dispositivo Android

Debajo del código trabajó para mí. Sólo algunas correcciones en el segundo fragmento.

 Intent resultIntent = new Intent(this, TestService.class); PendingIntent pi = PendingIntent.getActivity(this, 0, resultIntent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()) .setContentIntent(pi) .setAutoCancel(true) .setContentTitle("title") .setSmallIcon(R.drawable.ic_notif) //add a 24x24 image to the drawable folder // and call it here .setContentText("desc"); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); nm.notify(0, builder.build()); 
  • ¿Por qué los documentos de gcm recomiendan invalidar el registro en la actualización de la aplicación?
  • Gcm GoogleCloudMessaging nueva implementación
  • Mensaje de emisión extraño recibido en el inicio de la aplicación
  • Cómo implementar un GCM Hello World para Android con Android Studio
  • Enviar notificaciones mediante GCM en Android
  • El GCM de Android no funciona
  • ¿Recibiré mensajes de GCM si Android mata a mi aplicación y si hago un cierre de la configuración?
  • Notificaciones Push de XMPP (Openfire)
  • Servidor GCM con motor de aplicaciones de Google
  • Android: abre o reinicia la aplicación después de hacer clic en la notificación push mediante las actividades de bandera
  • Actividad refrescante al recibir la notificación de gcm push
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.