Android Alert manager delete - android

I have set an alert manager for every event created by user. If any user delete the event after that, I want to delete the alert manager set for the specific event. How to delete any specific alert programmatically?

I have set an alert manager for every event created by user.
I am going to assume that you really mean that you have set an alarm with AlarmManager.
How to delete any specific alert programmatically?
Call cancel() on AlarmManager with a PendingIntent for an equivalent Intent. Here is a sample project that demonstrates this (see OnBootReceiver.java).

Related

Cancel already set reminder and set new for new time zone

I am working on one android application which allows user to set reminder for specific task or work. and i have created reminder in android using alarm manager. But my problem is when user move to some other time zone how can i change reminder time as per new time zone ?
2nd problem is if user have set reminder for two task at same time which one will get canceled by system ?
As android doesn't provide id for reminder.
I have already checked link1, link2 questions on SO but it is not valid for me in my 2nd case.
You should not to do that becouse you set it up in abcolute unix time value right?
It means that the same absolute time event will happens in the same moment in every time zone
P.S to cancele alarm you should use the same Intent as you use whent setup alarm. It just override previous alarm by new one. In my application i use only one alarm for all events, and i invalidate it value every time and set it up to earliest event time

Allow users to disable notifications Android

I don't know if this can be done but I have a scheduler/diary app that allows the user to add/remove items. When the user adds an item, they are given an option to set a notification for either 1 hour, 30 mins, or 15 mins before the event time or else to not be notified. I am using an alarm manager with a broadcast receiver to handle this.
I want to display an option in the app menu to enable/disable notifications; i.e. if an alarm is scheduled to sound in 15 mins it should not happen. How can I implement this?
Take a look at NotificationManager class. When you set your notification you can provide a notification id like this:
mNotificationManager.notify(id, notification)
If you later want to cancel this notification(i.e. like in your case, if a user has selected an option to disable notifications) you would need to use
mNotificationManager.cancel(id)
Or you could use cancelAll() to cancel all notifications:
mNotificationManager.cancelAll ()
Let me know if this helps.

how to pop up alarm even when the application is closed

I'm developing a location based alarm which is an Android application.
All the coding part has been done.
But the alarm alert dialog is not displaying when the application is closed.
Please help me, I'm trying to pop up the alarm even when user is using another application or is in the home screen.
The code of my alarm at the moment is shown below:
final MediaPlayer mp = MediaPlayer.create(LocAlarmProject.this, R.raw.airtel);
mp.start();
// LocAlarmProject.this below is what's causing the problem:
final AlertDialog.Builder builder=new AlertDialog.Builder(LocAlarmProject.this);
builder.setTitle(disp_title);
builder.setMessage(disp_desc);
builder.setIcon(R.drawable.alarm);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mp.stop();
}
});
builder.show();
I am pretty sure you are looking for Service.
Copied and Paste:
A Service is an application component representing either an
application's desire to perform a longer-running operation while not
interacting with the user or to supply functionality for other
applications to use. Each service class must have a corresponding
declaration in its package's AndroidManifest.xml. Services
can be started with Context.startService() and Context.bindService().
Use Notification service to keep track of the status.....visit......http://developer.android.com/guide/topics/ui/notifiers/notifications.html
The proper way to do this requires a few steps. Sorry, it's not trivial if you haven't done it before:
First, you're going to use Android's built-in AlarmManager to schedule the time you want your app to be activated. You schedule a new alarm with the time to wake up and a PendingIntent.
Second, create your PendingIntent that's used to activate your app for the time to show the alarm.
Third, you can handle this Intent several ways, the most common is to create a class that extends BroadcastReceiver to receive the Intent. This class is notified when it's time to show the alarm. The Intent that you created and put inside your PendingIntent is passed to its onReceive() method. You pass this information to your app to display the alert dialog. --- You can alternatively just register your main app to receive the Intent instead, then override the onNewIntent(Intent) method in your Activity.
Four, register your BroadcastReceiver in your AndroidManifest.xml file. This is also the place to register this receiver to listen for the Intent you created. You do this using the <intent-filter> tag.
Five, (optional) if you want your alarm to display even if the phone is asleep, and you want to make sure it doesn't go back to sleep before the user acknowledges the alarm, you'll need to obtain a WAKE_LOCK to do so.
The reason this is preferable to using a Service is it doesn't consume resources just to wait for the alarm, and also it still works if Android decides to kill your app free up memory. Good luck and happy coding!

Group Status Bar Notifications - One Icon

I have up to 4 separate alarms. When an alarm goes off, I display a status bar notification. If I have 2 alarms go off at the same time, I want to have only 1 status bar icon. If I cancel one of the two alarms, I still want to see that single status bar icon (since there is still an alarm going off, even though I cancelled the first alarm). When I cancel the last alarm on the screen I want to remove the status bar icon.
Is there a built in way to do this or do I have to keep track of what alarms are on the screen and only dismiss the notification if it's the last alarm?
Thanks for your help.
What I understood that you want only latest notification to be displayed and if you cancel your last alarm all should go. Here is my solution:
Call the same notification function every time you set notification as it will replace the previous one.
Pass an argument to notification function in case you want to cancel the notification.
If a notification is alredy there and now you want to cancel the next alarm and you want the previous notification should be there, then you should maintain a variable in sharedpreference which will tell you not to cancel the previous notification.You should check this before calling notification function
When you cancel the last alarm then you can pass the argument to notification function as you cancel any other alarm.

Status bar Notification in android

I want to set a onClickListner for a status bar Notification. How it is possible ? Please help. Now i can load a Activity by using the pending intent. I like to set a onClickListner for the notificatioin.
Regards
Parvathi
It is not possible to set an OnClickListener for a notification. Because of the way notifications are handled/displayed there is no way to guarantee that the process that created the notification will be running at the time the notification is clicked. This means that any code you wrote to provide click handling may not be running.
If you need click listener style behavior you will have to do it using the PendingIntent: set it to start a Service that runs the logic or to use an Intent that is received by a BroadcastReceiver. This will let you perform activity without requiring a UI.

Categories

Resources