当日历在Android中触发了提醒警报的接收器时,如何获取事件ID?

时间:2014-01-27 22:30:29

标签: android

这是我的代码:

public class CalendarReminderReceiver extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equalsIgnoreCase(CalendarContract.ACTION_EVENT_REMINDER)) {
        //Do Something Here to get EVENT ID
    }

}

}

无论如何从广播接收器获取提醒事件的事件ID? 这是我的清单:

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

1 个答案:

答案 0 :(得分:6)

也许为时已晚,但这是我的解决方案:

if (intent.getAction().equalsIgnoreCase(CalendarContract.ACTION_EVENT_REMINDER)) {
    //Do Something Here to get EVENT ID
    Uri uri = intent.getData();

    String alertTime = uri.getLastPathSegment();

    String selection = CalendarContract.CalendarAlerts.ALARM_TIME + "=?";

    Cursor cursor = context.getContentResolver().query(CalendarContract.CalendarAlerts.CONTENT_URI_BY_INSTANCE, new String[]{CalendarContract.CalendarAlerts.EVENT_ID},selection,new String[]{alertTime}, null);

}