问题
I am implementing an application in which I have to display alarm info (day, time..) if it is available. Is there anybody know how to access to alarm info? Thanks so much
回答1:
Try something like this
final String tag_alarm = "tag_alarm";
Uri uri = Uri.parse("content://com.android.alarmclock/alarm")
Cursor c = getContentResolver().query(uri, null, null, null, null);
Log.i(tag_alarm, "no of records are" + c.getCount());
Log.i(tag_alarm, "no of columns are" + c.getColumnCount());
if (c != null) {
String names[] = c.getColumnNames();
for (String temp : names) {
System.out.println(temp);
}
if (c.moveToFirst()) {
do {
for (int j = 0; j < c.getColumnCount(); j++) {
Log.i(tag_alarm, c.getColumnName(j);
+ " which has value " + c.getString(j));
}
} while (c.moveToNext());
}
}
回答2:
Result: Finally, I can retrieve alarm information by using Curious's answer as above. Moreover, when I explored Deskclock app in /packages/apps/ I found one more way to get next alarm format (I used this way to display alarm info on my LockScreen because it is more simple than Curious's one :) )
String nextAlarm = Settings.System.getString(getContentResolver(),
Settings.System.NEXT_ALARM_FORMATTED);
if(TextUtils.isEmpty(nextAlarm) {
Log.v(TAG, "nextAlarm is empty");
} else {
Log.v(TAG, "nextAlarm is :" + nextAlarm);
}
The next alarm format like this:
Sat 09:00
The disadvantage point is that it can only run in system environment (you have to embed them to Android source -> build it and run by image file).
来源:https://stackoverflow.com/questions/13759077/get-alarm-infomation