Q
Q
Quartex2018-02-07 13:23:56
Java
Quartex, 2018-02-07 13:23:56

How to handle a click on a notification?

Hello everyone, there is a notification. I want to send information to the metric when clicked. I know how to open another activity by clicking on a notification, but I don’t know how easy it is to use the method as in a regular button.
PS method from the metric itself reportEvent("blah blah"). Thanks in advance

private void sentNotification(){
        Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("Закажите фотокнигу")
                .setContentText("И получите магнитик с Вашим фото")
                .setSound(uri)
                .setTicker("Подарок от ");
        Notification notification = builder.build();


        NotificationManager notificationManager =
                (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(0, notification);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri, 2018-02-07
@Quartex

Hmm, at least there are 2 ways:
1) fast. you make a transparent activity, which you kill directly in onCreate(), sending the metric along the way.
2) Make a custom notification, where you can hang the listener on the buttons.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question