2012-05-22 3 views
2

J'ai le code suivant .... comme la notification vient ... il montre toujours "1" et ne compte pas s'il y a plus de notifications .... ce que je fais faux?notification compte ne compte pas

Je vais le code a commencé à partir de:

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

Répondre

3

Vous définissez votre nombre comme count=1 et après avoir incrémenté notify.number par 1 ??? Je ne vois jamais vous incrémenter votre compteur lui-même ...

Vous pouvez essayer de le rendre statique en tant que membre et incrémenter à chaque fois comme ceci:

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); 
} 
+0

merci beaucoup !! – user1404924

+0

s'il vous plaît également considérer de prendre cela comme réponse acceptée, de sorte que d'autres recherches sur un problème similaire voir, que cette réponse peut les aider aussi. –

+0

heyy ... fonctionne bien, mais la valeur de compte n'est pas actualisée lorsque la notification a cliqué dans la barre de notification ... pls m'aider – lalith

1

Faire int count=1; mondiale à l'activité que vous avez déclaré NOTIFY_ME_ID. Vous déclarez le compte à l'intérieur givenotification() donc son initialisation avec 1 toujours.

Questions connexes