3

I am using the following code showing the notification, it works properly. I am look for the listener from which i can come to know whether the notification is expanded or not.

I want to open the app if the notification is expanded or else open the particular activity of the app.

                 Intent intent= new Intent(context, Activity1.class);
                 PendingIntent pendingIntent = PendingIntent.getActivity(context, getNextRandom(), intent, 0);
                 Builder newBuilder newBuilder = new Notification.Builder(context);
                 newBuilder.setContentTitle(title)
                 .setContentText(subtitle)
                 .setAutoCancel(true)
                 .setSmallIcon(R.drawable.icon)
                 .setTicker(notificationMessage)
                 .setContentIntent(pendingIntent);
                 Notificationnotification = new Notification.BigTextStyle(newBuilder)
                 .setBigContentTitle(notificationTitle)
                 .bigText(text)
                 .build();

Let me know if there is way to acheive this?

Fahim
  • 12,198
  • 5
  • 39
  • 57
  • The only way I see this happening is through the use of `RemoteViews`. Create your own layouts for default & expanded states. Set different on-click `PendingIntents` for each of these layouts. Finally, set `builder.setContent(defaultRemoteViews)`. And `notification.bigContentView = expandedRemoteViews;`. – Vikram Mar 21 '15 at 02:44

2 Answers2

2

There is no way to know if the notification is open... What you can do is add buttons to the expanded notification that pressing on them will act differently than pressing on the notification itself.

roiberg
  • 13,629
  • 12
  • 60
  • 91
  • But your case will not work in the case when the notification is expanded and I tap the notification and not the button – Fahim Mar 21 '15 at 06:55
  • You are right... but I started my answer with "There is no way to know if the notificatiom is open" – roiberg Mar 22 '15 at 07:26
1

There maybe no direct way, but maybe the following hack can help!!

You can have a custom notification layout and use RemoteView, Set a setOnClickPendingIntent to launch a service for the entire view so that you get notified when the notification is clicked.

When the user clicks the notification, service is started and show the new expanded custom layout from the service (you replace the old notification with the new one)

Maybe show your initial notification also from the same service using startforeground, so that your app is not killed and the view click can be received faster since service is already running and response time for changing the view is lower.

see this for remoteview and this for launching service from notification click.

Community
  • 1
  • 1
Deepu
  • 598
  • 6
  • 12