Reputation: 671
Here's code that's supposed to dismiss the alarm by it's label:
Intent intent = new Intent(AlarmClock.ACTION_DISMISS_ALARM);
intent.putExtra(AlarmClock.EXTRA_ALARM_SEARCH_MODE, AlarmClock.ALARM_SEARCH_MODE_LABEL);
//intent.putExtra(AlarmClock.ALARM_SEARCH_MODE_TIME,1);
//intent.putExtra(AlarmClock.EXTRA_IS_PM, true);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(AlarmClock.EXTRA_MESSAGE, "Label");
if(intent.resolveActivity(getPackageManager()) != null){
startActivity(intent);
} else {
Toast.makeText(SetAlarmActivity.this, "There is no app that support this action", Toast.LENGTH_SHORT).show();
}
Unfortunately, it just opens the default alarm app and doesn't even dismiss the alarm I need. How to make it work correctly?
Upvotes: 1
Views: 737
Reputation: 93728
That code is doing what it's supposed to do. It's opening the intent you specified- the alarm clock app.
I'm assuming you set an alarm via AlarmManager and want to cancel that? If so, the code is:
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent myIntent = new Intent(getApplicationContext(), YourBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
getApplicationContext(), REQUEST_CODE, myIntent, 0);
alarmManager.cancel(pendingIntent);
Make sure the request code is the same as you started.
If you actually set an alarm via the alarm app and wanted to cancel it- I'm not sure there is a way without involving the user.
Upvotes: 0