calendar events and alarmManager service in android

柔情痞子 提交于 2019-12-11 07:45:15

问题


I'm trying to create an application as follows:

The user inserts an event time and sets some actions to be done in this time like turning the phone to vibration mode in this period or turning off the wifi, so I will let the user insert his event data, and I will store it on the android calendar.

Then save the actions in database. What I need is a service that fires when a calendar event occurs so I can catch the event id and compare it with actions in my database and do the actions that the user needs.

Any help please???


回答1:


As far as I am aware, and I could be wrong, since the Calendar is not truly implemented at the Operating System level you can not tie directly into event triggers (Reminders, etc.) that you see on your phone when Events are coming up.

More or less, the Calendar app native to a phone is implemented by the device maker (HTS, Motorola, etc.), which means that the event trigger BroadCast Receiver (or Service) is not something you can tie into.

This will be different in Ice Cream Sandwich I believe as the Calendar API is being introduced....there aren't many 4.0 devices out there yet.




回答2:


This broadcast receiver works on my phone at least (have not tested others).

A. Using receiver in manifest.xml

<receiver android:name=".MyRemindersReceiver" >
            <intent-filter>
                <data android:scheme="content" />
                <action android:name="android.intent.action.EVENT_REMINDER" />
            </intent-filter>
</receiver>

B. Using receiver in code

    IntentFilter inFilter = new IntentFilter(CalendarContract.ACTION_EVENT_REMINDER);
    inFilter.addDataScheme("content");
    registerReceiver(myRemindersReceiver, inFilter);

Looking at this broadcast message in the debugger, it seems that this message has no extras in bundle. However it has a Uri in intent.getData(), which I assume to be the Uri for the calendar event. So you need to query this uri to get more information about the remainder event.



来源:https://stackoverflow.com/questions/8893660/calendar-events-and-alarmmanager-service-in-android

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