el recuento de notificaciones no cuenta
Frecuentes
Visto 2,203 veces
2
Tengo el siguiente código... cuando llega la notificación... siempre muestra "1" y no cuenta si hay más notificaciones... ¿qué estoy haciendo mal?
Voy al código que comenzó desde:
public class ActionSendSMS extends Activity {
private static final int NOTIFY_ME_ID=5476;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.actionsendsms);
givenotification(getBaseContext());
finish();
}
.... ....
public void givenotification(Context context){
//Get the notification manager
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager nm = (NotificationManager)context.getSystemService(ns);
//Create Notification Object
int count=1;
int icon = R.drawable.red_ball;
CharSequence tickerText = "Nice message!";
long when = System.currentTimeMillis();
final Notification notify = new Notification(icon, tickerText, when);
notify.flags |= Notification.DEFAULT_SOUND;
notify.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
notify.flags |= Notification.FLAG_AUTO_CANCEL;
notify.number += count;
//Set Notification send options
Intent intent = new Intent(context, ActionNotifySendMessage.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
notify.setLatestEventInfo(context, "Message Alert", tickerText, pi);
nm.notify(NOTIFY_ME_ID, notify);
}
2 Respuestas
3
Estableces tu conteo como count=1
y después de incrementar notify.number
por 1 ??? Nunca te veo incrementar tu propio contador...
Podría intentar hacerlo estático como miembro e incrementarlo cada vez de esta manera:
public class ActionSendSMS extends Activity {
private static final int NOTIFY_ME_ID=5476;
private static int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.actionsendsms);
sendSMS();
givenotification(getBaseContext());
finish();
}
public void givenotification(Context context){
//Get the notification manager
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager nm = (NotificationManager)context.getSystemService(ns);
//Create Notification Object
count++;
int icon = R.drawable.red_ball;
CharSequence tickerText = "PhoneFinder send GPS-message!";
long when = System.currentTimeMillis();
final Notification notify = new Notification(icon, tickerText, when);
notify.flags |= Notification.DEFAULT_SOUND;
notify.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
notify.flags |= Notification.FLAG_AUTO_CANCEL;
notify.number += count;
//Set Notification send options
Intent intent = new Intent(context, ActionNotifySendMessage.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
notify.setLatestEventInfo(context, "DroidFinder Alert", tickerText, pi);
nm.notify(NOTIFY_ME_ID, notify);
}
contestado el 22 de mayo de 12 a las 13:05
1
Marca int count=1;
global a la actividad como ha declarado NOTIFY_ME_ID
. Estás declarando contar dentro givenotification()
por lo que su inicialización con 1 siempre.
contestado el 22 de mayo de 12 a las 13:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas android count notifications notificationmanager or haz tu propia pregunta.
considere también tomar esto como una respuesta aceptada, para que otros que busquen un problema similar vean que esta respuesta también puede ayudarlos. - rafael t
hola... funciona bien pero el valor de conteo no se actualiza cuando se hace clic en la notificación en la barra de notificaciones... por favor ayúdenme - lalita