[英]How to know the position of notification in android
I am trying to display list of elements in notification bar. 我正在尝试在通知栏中显示元素列表。 Now I have a set of notifications but every notification I am clicking takes me to same activity ie I was not able to store the position of notification. 现在,我有一组通知,但是我单击的每个通知都将我带到相同的活动,即我无法存储通知的位置。
Here is my code 这是我的代码
if (list != null && !list.isEmpty()) {
for (int i = 0; i < list.size(); i++) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(
"Coupon Received From "
+ list.get(i).merchantName)
.setContentText(
"Coupon Value : "
+ list.get(i).couponValue)
.setAutoCancel(true)
.setTicker("Coupon alert message from Kluebook")
.setVibrate(new long[] { 100, 250, 100, 250 });
Intent resultIntent = new Intent(context,
CouponDetailActivity.class);
resultIntent.putExtra("couponid",
list.get(i).couponid);
resultIntent.putExtra("position", list.get(i).i);
resultIntent.putExtra("branchid",
list.get(i).issuedBranchid);
PendingIntent resultPendingIntent = PendingIntent.getActivity(
context, 0, resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotifyMgr = (NotificationManager) context
.getSystemService(context.NOTIFICATION_SERVICE);
mNotifyMgr.notify(i + 1, mBuilder.build());
}
} else {
System.out.println("+++++++++++ IT IS EMPTY +++++++++++++++ list");
}
}
If I get 5 notifications in notification bar, every notification takes me to first notification activity. 如果我在通知栏中收到5条通知,则每个通知会将我带到第一个通知活动。
Since you are using the same context to create all the notifications' PendingIntent, I think all these notifications are taking you to the same activity (in your case CouponDetailActivity). 由于您使用相同的上下文来创建所有通知的PendingIntent,因此我认为所有这些通知都将您带到同一活动(在您的情况下为CouponDetailActivity)。 So I would try creating different notifications with different Activity's context and pending intent and that should take you to your desired activity! 因此,我将尝试创建具有不同活动上下文和待定意图的不同通知,这将带您进入所需的活动!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.