我正在实现一个应用程序,在该应用程序中我必须显示警报信息(日期、时间..)如果可用的话。有没有人知道如何获取警报信息?非常感谢
发布于 2012-12-07 16:00:39
试试这样的东西
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());
}
}发布于 2012-12-10 17:45:39
结果:最后,我可以使用上面的好奇心的答案来检索警报信息。此外,当我在/packages/apps/中浏览Deskclock应用程序时,我发现了另一种获取下一个闹钟格式的方法(我使用这种方法在我的LockScreen上显示闹钟信息,因为它比好奇心的方法:)
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);
}下一个告警格式如下:
Sat 09:00缺点是它只能在系统环境下运行(你必须将它们嵌入到Android源代码->中,构建它并通过镜像文件运行)。
https://stackoverflow.com/questions/13759077
复制相似问题