zamroni hamim
zamroni hamim

Reputation: 555

Remove notification inside service android

I have a notification on one of my services. Below is the code:

Notification notification = new NotificationCompat.Builder(this)
                                .setContentIntent(contentIntent)
                                .setContentTitle("title")
                                .setContentText("content")
                                .setSmallIcon(R.drawable.ic_small_notif)
                                .setLargeIcon(bitmap)
                                .setSound(alarmSound)
                                .setColor(Color.parseColor("#999999"))
                                .build();

                        startForeground(100,
                                notification);

I still confused how to stop this programmatically when I want to. Any suggestions?

Upvotes: 1

Views: 2468

Answers (2)

Vyacheslav
Vyacheslav

Reputation: 27211

use stopForeground(true);

it works with foregroud tasks.

Upvotes: 4

Safal Kumar Ghimire
Safal Kumar Ghimire

Reputation: 318

try this

 NotificationManager manager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.cancel(mnotinotifId);
    manager.cancelAll();

Upvotes: 0

Related Questions