简体   繁体   English

有没有办法设置从Google日历到我的Android应用的推送通知?

[英]Is there a way to set up a push notification from Google Calendar to my android app?

I am using the Google Calendar API with the READ_CALENDAR permission to query certain soccer games from a calendar and display them integrated with results from my referee app. 我正在使用具有READ_CALENDAR权限的Google Calendar API,以从日历中查询某些足球比赛,并将其与我的裁判应用程序的结果集成在一起显示。 Currently I query the calendar onConnected which is not often enough if I add a new game in the user's calendar. 当前,我查询日历onConnected,如果我在用户的日历中添加新游戏,这是不够的。

Obviously I can requery the calendar API whenever I display data, but I was hoping to listen for a push notification from the Calendar API saying that a new event had been added. 显然,每当我显示数据时,我都可以重新查询日历API,但是我希望监听日历API发出的推送通知,说已添加了一个新事件。 The API here: https://developer.android.com/guide/topics/providers/calendar-provider.html doesn't mention anything. 这里的API: https : //developer.android.com/guide/topics/providers/calendar-provider.html没有提及任何内容。

However, here: https://developers.google.com/google-apps/calendar/v3/push talks about push notifications to your own server. 但是,这里: https : //developers.google.com/google-apps/calendar/v3/push讨论到您自己的服务器的推送通知。 Does anybody know a way to do the equivalent from an app? 有人知道可以通过应用程序执行等效操作的方法吗?

UPDATE from answer. 从答案更新。 Does this code look reasonable, especially with respect to leaking resources? 此代码看起来合理吗,尤其是在资源泄漏方面?

    private void updateGamesFromCalendar() {
    //get Calendar games if allowed
    if (checkCalendar()) {
        //Look for events with the keyword list in the Title, and dates between today-7 and today+7
        long nowMs = System.currentTimeMillis();
        String[] eventSelectionArgs = new String[]{Long.toString(nowMs - TimeUnit.DAYS.toMillis(7)),Long.toString(nowMs + TimeUnit.DAYS.toMillis(7)) };
        if ((mEventsCursor != null) && (mCalendarObserver != null)) mEventsCursor.unregisterContentObserver(mCalendarObserver);
        mEventsCursor = getContentResolver().query(RefWatchSettings.uriEvents, RefWatchSettings.EVENT_PROJECTION, RefWatchSettings.whereClauseEvents, eventSelectionArgs, RefWatchSettings.orderByEvents);
        if (mCalendarObserver == null) mCalendarObserver = new CalendarEventObserver(null);
        mEventsCursor.registerContentObserver(mCalendarObserver);

        //delete future Calendar games and replace with the new query
        Game.removeFutureCalendarGames(mGames);
        removeFutureCalendarGamesFromDataItem();

        getGamesFromCalendar();
        refreshGameFragments();
        sendFutureGameNotifications();
    }
}

Calendar events are retrieved with queries (see Google Doc ). 通过查询检索日历事件(请参阅Google Doc )。 Queries return Cursor objects (see Cursor JavaDoc ). 查询返回Cursor对象(请参见Cursor JavaDoc )。 And Cursor objects can be observed with registerContentObserver() . 并且可以使用registerContentObserver()观察Cursor对象。 So make a query on calendar events, register a Content Observer and let your Cursor open. 因此,对日历事件进行查询,注册一个内容观察者,然后打开您的Cursor。 You should receive updates of events through your Content Observer. 您应该通过内容观察器接收事件的更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以设置Google Assistant以使用Dialogflow向我的Android应用发送推送通知吗? - Can I set up Google Assistant to send a push notification to my Android app using Dialogflow? 如何从我的服务器推送通知到我的Android应用程序? - How to PUSH a notification from my server to my Android App? 使用我的Android应用中的GCM推送通知 - Push notification using GCM from my Android App 适用于iPhone和Android的文本应用程序的推送通知 - Push notification for my text app for iPhone and Android 有没有一种方法可以将日历约会从标准的android Google日历发送到另一个(android)应用程序? - Is there a way to send the calendar appointments from the standard android google calendar to another (android) app? 我可以使用Android推送通知在我的Android应用中设置值 - Can I use an Android Push Notification to set a value in my Android App 拦截来自另一个应用程序的推送通知android c2dm并在我的应用程序中使用通知 - Intercepting push notification android c2dm from another application and using the notification in my app 在android中设置推送通知 - Set Push Notification in android Android:从App查找推送通知设置 - Android: Find Push Notification Settings from App 从推送通知启动android应用 - Launch android app from push notification
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM