0

всем здрям.

Проблема такая: на входе есть некий список объектов, который формируется в сервисе. Нужно при получении этого списка сделать уведомления по одному на каждую позицию (из этого же сервиса).

Нотификации создаю, кидаю туда интенты, но при нажатии на интент открывается нужная активити и берет какую то ересь из этого интента.

Где я не прав?

  private void sendNotificationEarchNewItems(List<Map<String, Object>> newIrems) {

    final List<Map<String, Object>> locList = newIrems;

    final Handler uiHandler = new Handler(Looper.getMainLooper());

    uiHandler.post(new Runnable() {
        @Override
        public void run() {
            for (Map map : locList) {               
                final Context context = getApplicationContext();
                final String idd = map.get("_id").toString();

                final int NOTIF_ID = Integer.parseInt(idd.substring(0, 6));
                final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

                Intent intent = new Intent(getApplicationContext(), ItemActivity.class);
                intent.putExtra("_id", idd);
                PendingIntent pIntent = PendingIntent.getActivity(thisContext, 0, intent, 0);

                final Notification notification = new NotificationCompat.Builder(context)
                        .setSmallIcon(R.mipmap.ic_launcher) 
                        .setContentTitle(map.get("title").toString())
                        .setContentIntent(pIntent)
                        .build();

                notificationManager.notify(NOTIF_ID, notification);



                final RemoteViews contentView = notification.contentView;
                final int iconId = android.R.id.icon;                    
                Picasso.with(getApplicationContext()).load(map.get("mainImage").toString()).into(contentView, iconId, NOTIF_ID, notification);
            }
        }
    });


}
1
  • еще раз проанализировал отладчиком. "_ид", идущий в интент перезаписывается при каждом создании новой нотификации. значит надо передать в интент весь список и айди уведомления для сопоставления. но как отловить нажатие на уведомление? 5 окт 2016 в 9:19

1 ответ 1

2

У пендингинтента поставил одинаковые реквест коды. Вот с такой правкой все заработало.

 PendingIntent pIntent = PendingIntent.getActivity(thisContext, NOTIF_ID , intent, 0);

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.