Nickthegoatboy
Nickthegoatboy

Reputation: 122

Android Clock App Set Alarm

I need to know if this is possible, and if it is, how I should proceed.

I'd like to make an app that will create a repeating alarm within the stock Android Clock App. It should go off at 8am each morning and should only take one button to activate within my app.

Thanks in advance

Upvotes: 1

Views: 1876

Answers (2)

Mori
Mori

Reputation: 4611

I found this way for Clock

public void createAlarm(String message, int hour, int minutes) {
    Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM)
            .putExtra(AlarmClock.EXTRA_MESSAGE, message)// show on it
            .putExtra(AlarmClock.EXTRA_HOUR, hour) //24 hours
            .putExtra(AlarmClock.EXTRA_MINUTES, minutes); //not more than 60 :)
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

Upvotes: 1

zombie
zombie

Reputation: 5259

Try this:

public void createAlarm(String message, int hour, int minutes) {
    Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM)
            .putExtra(AlarmClock.EXTRA_MESSAGE, message)
            .putExtra(AlarmClock.EXTRA_HOUR, hour)
            .putExtra(AlarmClock.EXTRA_MINUTES, minutes);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

Source: https://developer.android.com/guide/components/intents-common.html

Upvotes: 3

Related Questions