android 通知id,Android:获取通知的唯一ID

我相信你不应该立即为用户提供这么多通知。 您应该显示一条通知,整合有关事件组的信息,例如Gmail客户端。 为此目的使用Notification.Builder 。

NotificationCompat.Builder b = new NotificationCompat.Builder(c); b.setNumber(g_push.Counter) .setLargeIcon(BitmapFactory.decodeResource(c.getResources(), R.drawable.list_avatar)) .setSmallIcon(R.drawable.ic_stat_example) .setAutoCancel(true) .setContentTitle(pushCount > 1 ? c.getString(R.string.stat_messages_title) + pushCount : title) .setContentText(pushCount > 1 ? push.ProfileID : mess) .setWhen(g_push.Timestamp) .setContentIntent(PendingIntent.getActivity(c, 0, it, PendingIntent.FLAG_UPDATE_CURRENT)) .setDeleteIntent(PendingIntent.getBroadcast(c, 0, new Intent(ACTION_CLEAR_NOTIFICATION), PendingIntent.FLAG_CANCEL_CURRENT)) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE) .setSound(Uri.parse(prefs.getString( SharedPreferencesID.PREFERENCE_ID_PUSH_SOUND_URI, "android.resource://ru.mail.mailapp/raw/new_message_bells")));

如果你仍然需要有很多状态栏通知,你应该在某个地方保存你的计数器的最后一个值,并像这样使用for循环:

int counter = loadLastCounterValue(); for(String s : sList){ Notification notification = new NotificationCompat.Builder(this).setContentTitle("Title").setContentText(s).setSmallIcon(R.drawable.ic_launcher).setContentIntent(pendingIntent).build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(++counter, notification); } saveCounter(counter);

但正如我所说,我认为这是一个糟糕的解决方案,导致您的应用程序的用户体验不佳。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值