在屏幕上单击多个通知时如何显示与特定通知有关的内容

时间:2019-02-24 09:42:12

标签: android

问题:单击任何通知会将数据带到最新通知。 (以防屏幕上有来自我的应用程序的多个通知)

我希望在单击任何通知时提取与之相关的数据。

intentscore = new Intent(this, Main.class);
            intentscore.putExtra("type", messageBody);
            intentscore.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

 NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            String id = "id_product";
            CharSequence name = "Product";
            String description = "Notifications regarding our products";
            int importance = NotificationManager.IMPORTANCE_MAX;
            @SuppressLint("WrongConstant") NotificationChannel mChannel = new NotificationChannel(id, name, importance);
            mChannel.setDescription(description);
            mChannel.enableLights(true);
            mChannel.setLightColor(Color.RED);
            notificationManager.createNotificationChannel(mChannel);
            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), "id_product")
                    .setSmallIcon(R.drawable.ic_logo) //your app icon
                    .setBadgeIconType(R.drawable.ic_logo) //your app icon
                    .setChannelId(id)
                    .setContentTitle(messageTitle)
                    .setAutoCancel(true)
                    .setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, intentscore, PendingIntent.FLAG_UPDATE_CURRENT))
                    .setStyle(new NotificationCompat.BigPictureStyle()
                     .bigPicture(i)
                     .setBigContentTitle("My Application"))
                    .setContentText(messageBody)
                    .addAction(R.drawable.ic_remove_red_eye_black_24dp, "Read Article", PendingIntent.getActivity(getApplicationContext(), 0, intentscore, PendingIntent.FLAG_UPDATE_CURRENT))
                    .addAction(R.drawable.ic_close_black_24dp, "Delete", btPendingIntent)
                    .setWhen(System.currentTimeMillis())
                    .setOngoing(true);
            notificationManager.notify(Integer.parseInt(idNotify), notificationBuilder.build());

0 个答案:

没有答案