android - Auto Cancel Custom Notification using RemoteView -


I have created a custom layout notification using RemoteView is facing the problem, after the user touches it How To Cancel Notification Automatically I tried some things, but any one is giving the desired result

Find the code below:.

  RemoteViews remoteView = new RemoteViews (this.getPackageName (), R.layout. Notification_layout); NotificationCompat.Builder Builder = New Notification Compat.Builder (MainActivity.This); Builder.setSmallIcon (R.drawable.ic_launcher); Intent = intent (new activity), this is the second activity. Pending Prntent Piaiantient = pending Aitiaktivti (Menaktivitikis, Arkyuensisiidii, intent, Lmbitintent. Felajiansianelelaananaraanananaraanaanti); RemoteView.setOnClickPendingIntent (R.id.btnNotification, pIntent); Builder.setAutoCancel (right); Builder.setContent (remoteView); Notification = Inform the creator. Build (); Notify.flags | = Notice FLAG_AUTO_CANCEL; Notification Manager Manager = (Notification Manager) getSystemService (reference. NETIFICATION_SERVICE); NotiManager.notify (NOTY_ID, notify);    

The way I have achieved it by creating BroadcastReceiver The control button clicks on the notification and creates something like this:

  Public Class NotificationButtonListener BroadcastReceiver {@Override Public Zero onReceive (Reference Reference, Intent Intent) {int Action = intent.getIntExtra ("mode", -1); Do not forget to add your  BroadcastListener  to your manifest file (switches) {// do some things on the basis of action if there are more stuff}}}   

: & lt; Receiver Android: name = "NotificationButtonListener" & gt;

And you can create an assistant class to create and cancel the information:

  Public category notificationHelper {personal fixed final difference NOTIFICATION_ID = 5; Private Static Notification Manager mNotificationManager = null; Public Static Zero Shows Notification (Reference Reference) {mNotificationManager = (Notification Manager) context.getSystemService (context.NOTIFICATION_SERVICE); Remote power content view = new remote power (context.getPackageName (), R. layout; custom_notification_layout); ContentView.setOnClickPendingIntent (R.id.btn_close, Closed PendingIntent); Intent mMainIntent = new intent (reference, MainActivity.class); MMainIntent.setFlags (Int. FLAG_ACTIVITY_SINGLE_TOP | Intent. FLAG_ACTIVITY_NEW_TASK); Pending anticipated MMNEpendingTent = Pending ITActivity (references, 555, MMI, pending, andend.FLAG_UPDADERTNT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder (reference) .setTicker ( "play") .setContent (contentView) .setAutoCancel (wrong) .setOngoing (right) .setSmallIcon (R.drawable.ic_av_play) .setContentIntent (mMainPendingIntent); Notification Notification = mbuilder.build (); MNotificationManager.notify (NOTIFICATION_ID, Notification); } Public static void cancellation () (if (mNotificationManager! = Null) {mNotificationManager.cancelAll ();}}}   

and NotificationButtonListener using that class in your You can call NotificationHelper.cancelNotification ();.

Hope this helps you!

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -