Android 通知计数为';t计数
我有以下代码。。。。当通知到来时,它总是显示“1”,如果有更多的通知则不计算在内。。。。我做错了什么 我将从以下代码开始:Android 通知计数为';t计数,android,count,notifications,notificationmanager,Android,Count,Notifications,Notificationmanager,我有以下代码。。。。当通知到来时,它总是显示“1”,如果有更多的通知则不计算在内。。。。我做错了什么 我将从以下代码开始: public class ActionSendSMS extends Activity { private static final int NOTIFY_ME_ID=5476; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceS
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();
}
。。。。
使
int计数=1代码>全局到您声明的活动通知我\u ID
。您正在givenotification()中声明count,因此其初始化总是使用1。Makeint count=1代码>全局到您声明的活动通知我\u ID
。您正在givenotification()
内声明count,因此其初始化始终为1。您将计数设置为count=1
,然后将notify.number
增加1???
我从来没有看到你增加你的计数器本身
您可以尝试将其作为成员设置为静态,并每次按如下方式递增:
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);
}
您将计数设置为count=1
,然后将notify.number
增加1???
我从来没有看到你增加你的计数器本身
您可以尝试将其作为成员设置为静态,并每次按如下方式递增:
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);
}
也请考虑把这个当作一个被接受的答案,以便其他人在一个类似的问题上看到,这个答案也可以帮助他们。工作正常,但在通知栏中单击通知时不会刷新计数值。。。请帮助我也考虑把这个作为接受的答案,以便其他人在类似的问题上看到,这个答案也可以帮助他们。工作正常,但在通知栏中单击通知时不会刷新计数值。。。请帮帮我