Dim
Dim

Reputation: 4807

Force Android notification to open

How can I (if its possible) to force open notification? Like in incoming call on reminder notification?

 Intent intent = new Intent(context, ResultActivity.class);
            PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationCompat.Builder b = new NotificationCompat.Builder(context);

            b.setAutoCancel(true)
                    .setDefaults(Notification.DEFAULT_ALL)
                    .setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setTicker("Hearty365")
                    .setContentTitle("Default notification")
                    .setContentText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
                    //.setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND)
                    .setContentIntent(contentIntent)
                    .setContentInfo("Info")
            .addAction(android.R.drawable.ic_media_pause, "Start", contentIntent)
                    .addAction(android.R.drawable.ic_dialog_alert, "Pause", contentIntent);



            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(1, b.build());

enter image description here

Upvotes: 1

Views: 767

Answers (2)

earthw0rmjim
earthw0rmjim

Reputation: 19417

As far as i know you cannot open (click on) a notification programmatically.

The closest thing you can do is expand the notifications panel.

For expanding the notifications panel see this answer.

Upvotes: 1

Kaushal Kishor
Kaushal Kishor

Reputation: 481

Hi @Dim only you have to add one line in your Notification Builder.

.setOngoing(true)

Hopefully it will work. :)

Upvotes: 0

Related Questions