1

I am working on an android app and I am setting an alarm using the following code:

Intent i = new Intent(AlarmClock.ACTION_SET_ALARM); i.putExtra(AlarmClock.EXTRA_HOUR, 0); i.putExtra(AlarmClock.EXTRA_MINUTES, 0);

It works, but how can I deactivate this alarm?

starskythehutch
  • 3,328
  • 1
  • 25
  • 35
  • pls post your code including pendingIntent or how you set the alarm, its not just Intent i... right? – Pararth Feb 10 '14 at 12:43
  • Intent i = new Intent(AlarmClock.ACTION_SET_ALARM); i.putExtra(AlarmClock.EXTRA_HOUR, 0); i.putExtra(AlarmClock.EXTRA_MINUTES, 0); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); – user3030546 Feb 10 '14 at 12:47
  • 2
    http://stackoverflow.com/questions/12814658/how-to-cancel-alarmclock-that-was-created-by-my-app – Pararth Feb 10 '14 at 12:51

1 Answers1

0

try this code..,may be it helps you.

 buttonStop.setOnClickListener(new Button.OnClickListener(){

 @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
 Intent myIntent = new Intent(getBaseContext(),
  MyScheduledReceiver.class);

 PendingIntent pendingIntent
= PendingIntent.getBroadcast(getBaseContext(),
   0, myIntent, 0);

 AlarmManager alarmManager
 = (AlarmManager)getSystemService(ALARM_SERVICE);

 alarmManager.cancel(pendingIntent);

Intent intent = new Intent();
 intent.setClass(MyScheduledActivity.this,
  AndroidScheduledActivity.class);
 startActivity(intent);
  finish();
}});

here you can use pending intent for stopping alarm.

rajshree
  • 790
  • 5
  • 19