Uso el NotificationCompat.Builder
para mostrar mi notificación a través de las versiones de Android y utilizar un diseño personalizado para la notificación.
El diseño personalizado funciona bien en Android 3 y versiones posteriores (Nivel API 11), pero no se muestran en API Nivel 10 o inferior. Lo probé en 2.3 y 2.2 en el emulador.El diseño de notificación personalizada no funciona en Android 2.3 o inferior
Aquí está mi código:
Builder builder = new NotificationCompat.Builder(getApplicationContext());
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_layout);
contentView.setImageViewResource(R.id.notImage, R.drawable.stat_icon);
contentView.setTextViewText(R.id.notTitle, getResources().getString(R.string.streamPlaying));
contentView.setTextViewText(R.id.notText, StartActivity.streamName + " " + getResources().getString(R.string.playing));
builder
.setContentTitle(getResources().getString(R.string.streamPlaying))
.setContentText(StartActivity.streamName + " " + getResources().getString(R.string.playing))
.setSmallIcon(R.drawable.stat_icon)
.setContentIntent(pendingIntent)
.setOngoing(true)
.setWhen(0)
.setTicker(StartActivity.streamName + " " + getResources().getString(R.string.playing))
.setContent(contentView);
not = builder.build();
muy básico. El archivo de diseño es correcto, es el mismo que en el tutorial de notificación en android.com, para asegurarse de que no cometí un error allí. ;)
Recuerde: funciona bien en 3.0 y arriba, pero no en 2.3 o menos.
Oh sí. Loco. Muchas gracias, lo intentaré. – Leandros
El diseño funciona hasta ahora en 2.3 y versiones anteriores, pero no puedo hacer clic en el botón que agregué. Esto funciona solo en Android 3 y superior ... – Leandros
@Leandros, el soporte para hacer clic en botones en las notificaciones no se agregó hasta Android 3.0. – Justin