Programmatically ending an ongoing notification - Android

情到浓时终转凉″ 提交于 2019-12-05 11:34:54

I haven't done much with notifications but you might try this:

NotificationManager.cancel(id); // Where 'id' is the id of your notification

Replacing NotificationManager with the name of your instance of it, of course.

docs: http://developer.android.com/reference/android/app/NotificationManager.html#cancel%28int%29

Or this:

Notification.Builder.setAutoCancel(true);

http://developer.android.com/reference/android/app/Notification.Builder.html#setAutoCancel%28boolean%29

Start

int id = 01;
NotificationCompat.Builder mBuilder =
      new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .setContentTitle(getResources().getString(R.string.service_header))
        .setContentText("Connect to: http://" + httpd.getip() + ":8080")
        .setContentIntent(pendingIntent)
        .setOngoing(true);

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(01, mBuilder.build());

Cancel

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(01);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!