Get alarm infomation

大憨熊 提交于 2019-12-08 10:37:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!