Text after "
The code below is suggested by "iamverysmart" and working like a charm of it.
But now,
What do you think if you have canceled the notification?
Thank you in advance
Private Zero addNotification () pre {NotificationCompat.Builder Builder = New NotificationCompat.Builder (this) .setSmallIcon (R.drawable.icon1). SetContentTitle ("Notifications Example") .setContentText ("This is a test notification"); Influence notification = new intent (this, MyActivity.class); Pending content contentent = pending IT activation (this, 0, notification issued, pending notice. FLAG_UPDATE_CURRENT); Builder.setContentIntent (contentIntent); // Add notification notification as notification manager manager = (notification manager) getSystemService (reference .NETIFICATION_SERVICE); Manager.notify (FM_NOTIFICATION_ID, builder.build ()); }
Most of this code is inspired so that you do more research before asking
Add a toggle button to your XML
& lt; ToggleButton Android: id = "@ + id / myButton" Android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: textOn = "on" Android: textOff = "off" Android: onClick = "myButtonClicked" /> ;
Then onclick the method we call our notification method
public zero myButtonClicked {see} {boolean ison = ((ToggleButton) view.findViewById (R. Id.myButton)) isChecked () .; If (isOn) {// do stuff} else {addNotification ()}}
the actual notification method. FM_NOTIFICATION_ID is a constant integer
Private Zero addNotification () {NotificationCompat.Builder Builder = New NotificationCompat.Builder (this) .setSmallIcon (R.drawable.icon1) .setContentTitle ("Notifications Example") .setContentText ("This is a test notification"); Influence notification = new intent (this, MyActivity.class); Pending content contentent = pending IT activation (this, 0, notification issued, pending notice. FLAG_UPDATE_CURRENT); Builder.setContentIntent (contentIntent); // Add notification notification as notification manager manager = (notification manager) getSystemService (reference .NETIFICATION_SERVICE); Manager.notify (FM_NOTIFICATION_ID, builder.build ()); }
Removing the notification
Private Zero removeNotification () {NotificationManager Manager = (NotificationManager) getSystemService (Context.NOTIFICATION_SERVICE); Manager.cancel (FM_NOTIFICATION_ID); }
I'm not sure what "the user chose on the date chosen." Do you want to send a notification when the user uses the toggle button? That's included in myButtonClicked method to be more precise about what you mean.
No comments:
Post a Comment