-
Notifications
You must be signed in to change notification settings - Fork 101
CyanogenMod Alarm Clock
We have added support for querying and manipulating alarms within the CyanogenMod DeskClock application from the CM Platform SDK.
See the CyanogenModAlarmClock class for documentation about the alarm clock functionality.
First, your application must first declare the set alarm permission in AndroidManifest.xml:
<uses-permission android:name="android.permission.SET_ALARM" />
To create a new alarm, call createIntent(context) to construct an Intent with the set alarm action. Then, specify the time and other options following the instructions for the extras referenced in the set alarm action. This Intent is guaranteed to be delivered to the system Clock application.
Intent intent = CyanogenModAlarmClock.createAlarmIntent(CMAlarmClockTest.this);
intent.putExtra(AlarmClock.EXTRA_HOUR, 13);
intent.putExtra(AlarmClock.EXTRA_MINUTES, 35);
intent.putExtra(AlarmClock.EXTRA_MESSAGE, "Test from third party!");
intent.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
startActivityForResult(intent, 0);
First, your application must first declare the read alarms permission in AndroidManifest.xml:
<uses-permission android:name="cyanogenmod.alarmclock.READ_ALARMS" />
Then, you can query the alarms ContentProvider directly by referencing the URIs and database contract contained in ClockContract.
For example, to query all alarms and dump them to a log, you can query like this:
private static final String[] ALARM_QUERY_COLUMNS = {
ClockContract.AlarmsColumns._ID,
ClockContract.AlarmsColumns.LABEL,
ClockContract.AlarmsColumns.VIBRATE,
ClockContract.AlarmsColumns.RINGTONE,
ClockContract.AlarmsColumns.INCREASING_VOLUME,
ClockContract.AlarmsColumns.PROFILE,
ClockContract.AlarmsColumns.ENABLED
};
Uri clockUri = ClockContract.AlarmsColumns.CONTENT_URI;
Cursor allAlarms = getContentResolver().query(clockUri,
ALARM_QUERY_COLUMNS, null, null, null);
Log.d(TAG, "All alarms: " + DatabaseUtils.dumpCursorToString(allAlarms));
if (allAlarms != null && !allAlarms.isClosed()) {
allAlarms.close();
}
First, your application must first declare the modify alarms permission in AndroidManifest.xml:
<uses-permission android:name="cyanogenmod.alarmclock.MODIFY_ALARMS" />
To set an alarm to enabled or disabled, just construct an Intent with the appropriate extras from CyanogenModAlarmClock to specify the id and desired state. You can retrieve the rows containing alarms and their IDs by querying the ClockProvider as specified above. By calling startActivity with this Intent, the Clock application will perform the modification for you, as long as you hold the MODIFY_ALARMS permission.
Intent intent = new Intent(CyanogenModAlarmClock.ACTION_SET_ALARM_ENABLED);
intent.putExtra(CyanogenModAlarmClock.EXTRA_ALARM_ID, alarmId);
intent.putExtra(CyanogenModAlarmClock.EXTRA_ENABLED, true);
startActivity(intent);