简体   繁体   English

如何知道通知在Android中的位置

[英]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.

相关问题 在Android我怎么知道当前的通知id清除通知 - In Android how can i know the current notification id to clear the notification Android App - 如何设置 OpenFeint 通知 Position - Android App - How to Set OpenFeint Notification Position 如何知道触摸位置是否在特定区域中-Android - How to know if touch position is in a specific area - Android 如何知道Android中Firebase通知中的哪个主题名称? - How to know which topic name in Firebase Notification in Android? 如何从通知或应用程序图标单击android知道应用程序打开? - How to know app open from notification or app icon click android? 如何知道应用程序是否从Android通知托盘中打开? - How to know if the app is open from the android notification tray? 如何知道Android Notification大图片风格的图片大小? - How to know the picture size in the Android Notification big picture style? 我如何知道要显示或不显示通知的Android应用程序的应用程序状态? - How can I know the application state of an Android App to display or not a notification? 如何以编程方式知道是否在 Android O 上启用了通知渠道? - How can I know programmatically if a notification channel is enabled on Android O? 如何知道是否通过Android上的通知启动了应用/游戏? - How to know if app/game was launched via notification on Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM