Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to Hide notification after tap in android application

This is the code that gives notification on start of service

NotificationCompat.Builder mbuild = new NotificationCompat.Builder(getApplicationContext());

Intent in = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent resultIN =   PendingIntent.getActivity(getApplicationContext(),code,in,NOTIFICATION_COUNT);           mbuild.setSmallIcon(R.drawable.images1);    
mbuild.setContentText(NOTIFICATION_COUNT +" New Message");
mbuild.setContentIntent(resultIN);          //mbuild.addAction(R.drawable.notifications,NOTIFICATION_COUNT +"New Messages",resultIN);

 NotificationManager nmagr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nmagr.notify(1, mbuild.build());

everyting is working correct ..the code opens the target activity but the notification still stays there in the notification bar. i have tried useing mbuil.setautocancel(true); but its doing nothing

like image 648
Deepti Avatar asked Mar 06 '14 07:03

Deepti


People also ask

How do I hide app notifications on Android?

Open your phone's Settings app. Notifications. Under "Lock screen," tap Notifications on lock screen or On lock screen. Choose Don't show notifications.

How do I hide content of notifications on Samsung?

If you're running Android on a Samsung Galaxy smartphone, open the Settings app, scroll down, and tap on Lock screen. Next, tap on Notifications and not the switch next to it. To hide the message content in the Notification bar, make sure the Hide content switch is turned on.


1 Answers

try this

NotificationManager nmagr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            Notification notification=mbuild.build();
            notification.flags = Notification.FLAG_AUTO_CANCEL;
            nmagr.notify(1,notification);
like image 166
Santhosh Avatar answered Sep 20 '22 05:09

Santhosh