1

public class LayoutActivity extends AppCompatActivity { Button notifybtn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_layout);

    notifybtn=(Button) findViewById(R.id.button_noti);
    notifybtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent();
            PendingIntent pIntent = PendingIntent.getActivity(LayoutActivity.this,0,intent,0);
            Notification noti = new Notification.Builder(LayoutActivity.this)
                    .setTicker("Ticker Title")
                    .setContentTitle("Content Title")
                    .setContentText("Bus has Arrived at the station")
                    .setSmallIcon(R.drawable.aaa)
                    .addAction(R.drawable.aaa,"Available",pIntent)
                    .addAction(R.drawable.aaa,"NotAvailable",pIntent)
                    .setContentIntent(pIntent).getNotification();

            noti.flags = Notification.FLAG_AUTO_CANCEL;
            NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            nm.notify(0,noti);
        }
    });
}

}

make the notification dissapear in 15min? and does small icon support any type of image?

  • Does this answer your question? [How to remove the notification after the particular time in android?](https://stackoverflow.com/questions/5399229/how-to-remove-the-notification-after-the-particular-time-in-android) – grrigore Feb 26 '21 at 10:59

1 Answers1

-1

For Notification.Builder, I believe you need to set setTimeoutAfter.

Bink
  • 1,934
  • 1
  • 25
  • 41