Roberto Leinardi
Roberto Leinardi

Reputation: 14389

Notification.Builder and FLAG_INSISTENT

I like the ease of use of Notification.Builder but it seems not support the insistent mode of notifications.

Is there a way to set the flag FLAG_INSISTENT from the Notification.Builder?

Upvotes: 3

Views: 7180

Answers (2)

Kiwi
Kiwi

Reputation: 181

Maybe my answer can be useful to someone else

You can use:

NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext());

builder.setContentTitle("Title")
       .setContentText("Hello world")
       .setSmallIcon(R.mipmap.ic_launcher);

Notification notification = builder.build();
notification.flags = Notification.FLAG_INSISTENT;
final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(ID, notification)

Upvotes: 4

CommonsWare
CommonsWare

Reputation: 1006869

Not directly. There is a private setFlag() method on Notification.Builder -- I do not know why they did not expose it.

However, you can configure the rest of the Notification via a Builder, then adjust the flags on the completed Notification object.

Or, grab the code for Notification.Builder and modify it to create your own that exposes setFlag(), or adds setInsistent(), etc.

Upvotes: 14

Related Questions