谷歌中国开发者社区 (GDG)
  • 主页
  • 博客
    • Android
    • Design
    • GoogleCloud
    • GoogleMaps
    • GooglePlay
    • Web
  • 社区
    • 各地社区
    • 社区历史
    • GDG介绍
    • 社区通知
  • 视频
  • 资源
    • 资源汇总
    • 精选视频
    • 优酷频道

Semantic Time support now available on the Awareness APIs

2017-06-17adminAndroidNo comments

Posted by Ritesh Nayak M, Product Manager

Last year at I/O we launched the Awareness API, a simple yet
powerful API that let developers use signals such as Location, Weather, Time and
User Activity to build contextually relevant app experiences.

Available via Google Play services, the Awareness API offers two ways to take
advantage of context signals within your app. The Snapshot
API
lets your app request information about the user’s current context,
while the Fence
API
lets your app react to changes in user’s context, and when it matches a
certain set of conditions. For example, “tell me whenever the user is walking
and their headphone is plugged in”.

Until now, you could specify a time fence on the Awareness APIs but were
restricted to using absolute/canonical representation of time. Based on
developer feedback, we realized that the flexibility of the API in regards to
building time fences did not support higher level abstractions people use when
they think and talk about time. “This weekend“, “on the next
holiday
“, “after sunset“, are all very common and colloquial ways
of expressing time. That’s why we’re adding Semantic time support to these APIs
starting today

For e.g., if you were building a fitness app and wanted a way to prompt users
everyday morning to start their routine, or if you’re a reading app that wants
to turn on night mode after dusk; you would have to query a 3p API for
sunrise/sunset information at the user location and then write up an Awareness
fence with those canonical time values. With our latest update, you can use our
TIME_INSTANT_SUNRISE
and TIME_INSTANT_SUNSET
constants and let the platform manage all the complexity for you.

Let’s look at an example. Suppose you’re building a fitness app which prompts
users on Tuesday, and Thursday around sunrise to begin their morning work out.
You can set up this triggering using the following lines of code.

// A sun-state-based fence that is TRUE only on Tuesday and Thursday during Sunrise 
AwarenessFence.and(
    TimeFence.aroundTimeInstant(TimeFence.TIME_INSTANT_SUNRISE,
            -10 * ONE_MINUTE_MILLIS, 5 * ONE_MINUTE_MILLIS),
    AwarenessFence.or(
        TimeFence.inIntervalOfDay(TimeFence.DAY_OF_WEEK_TUESDAY,
                0, ONE_DAY_MILLIS),
        TimeFence.inIntervalOfDay(TimeFence.DAY_OF_WEEK_THURSDAY,
                0, ONE_DAY_MILLIS)));

One of our favorite semantic time features is public holidays. Every country and
regions within it have different holidays. Assume you were a local hiking &
adventure app that wants to show users activities they can indulge in on a
holiday that falls on a Friday or a Monday. You can use a combination of Days
and Holiday flags to identify this state for all your users around the world.
You can do this with just 3 lines of code and have this work in any part of the
world.

// A local-time fence that is TRUE only on public holidays in the
// device locale that fall on Fridays or Mondays.
AwarenessFence.and(
    TimeFence.inTimeInterval(TimeFence.TIME_INTERVAL_HOLIDAY),
    AwarenessFence.or(
        TimeFence.inIntervalOfDay(TimeFence.DAY_OF_WEEK_FRIDAY,
                9 * ONE_HOUR_MILLIS, 11 * ONE_HOUR_MILLIS),
        TimeFence.inIntervalOfDay(TimeFence.DAY_OF_WEEK_MONDAY,
                9 * ONE_HOUR_MILLIS, 11 * ONE_HOUR_MILLIS)));

In both example cases, Awareness does the heavy lifting of localizing time and
holidays based on the device locale settings.

We’re excited to see what problems you’ll solve using this powerful API. Please
join our mailing
list
to get updates about this and other Context APIs at Google.

.blogimage img {
width: 100%;
}



Source: Semantic Time support now available on the Awareness APIs

除非特别声明,此文章内容采用知识共享署名 3.0许可,代码示例采用Apache 2.0许可。更多细节请查看我们的服务条款。

Tags: Android

Related Articles

Notifying your users with FCM

2018-09-19admin

Saving Data: Reducing the size of App Updates by 65%

2016-12-07admin

A look back at the most read Google Play posts on Medium in 2017

2017-12-29admin

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Recent Posts

  • Setting a course to the future of cloud computing
  • Analyze this—expanding the power of your API data with new Apigee analytics features
  • Hello, .dev!
  • Google announces intent to acquire Alooma to simplify cloud migration
  • Google announces intent to acquire Alooma to simplify cloud migration

Recent Comments

  • Chen Zhixiang on Concurrent marking in V8
  • admin on 使用 Android Jetpack 加快应用开发速度
  • 怪盗kidou on 使用 Android Jetpack 加快应用开发速度
  • 鸿维 on Google 帐号登录 API 更新
  • admin on 推出 CVPR 2018 学习图像压缩挑战赛

Archives

  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • May 2016
  • April 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • January 1970

Categories

  • Android
  • Design
  • Firebase
  • GoogleCloud
  • GoogleDevFeeds
  • GoogleMaps
  • GooglePlay
  • Google动态
  • iOS
  • Uncategorized
  • VR
  • Web
  • WebMaster
  • 社区
  • 通知

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

最新文章

  • Setting a course to the future of cloud computing
  • Analyze this—expanding the power of your API data with new Apigee analytics features
  • Hello, .dev!
  • Google announces intent to acquire Alooma to simplify cloud migration
  • Google announces intent to acquire Alooma to simplify cloud migration
  • New UI tools and a richer creative canvas come to ARCore
  • Introducing PlaNet: A Deep Planning Network for Reinforcement Learning
  • AI in depth: monitoring home appliances from power readings with ML
  • AI in depth: monitoring home appliances from power readings with ML
  • AI in depth: monitoring home appliances from power readings with ML

最多查看

  • 谷歌招聘软件工程师 (21,022)
  • Google 推出的 31 套在线课程 (20,113)
  • 如何选择 compileSdkVersion, minSdkVersion 和 targetSdkVersion (18,698)
  • Seti UI 主题: 让你编辑器焕然一新 (12,684)
  • Android Studio 2.0 稳定版 (8,963)
  • Android N 最初预览版:开发者 API 和工具 (7,934)
  • 像 Sublime Text 一样使用 Chrome DevTools (5,949)
  • Google I/O 2016: Android 演讲视频汇总 (5,519)
  • 用 Google Cloud 打造你的私有免费 Git 仓库 (5,500)
  • 面向普通开发者的机器学习应用方案 (5,200)
  • 生还是死?Android 进程优先级详解 (4,971)
  • 面向 Web 开发者的 Sublime Text 插件 (4,137)
  • 适配 Android N 多窗口特性的 5 个要诀 (4,103)
  • 参加 Google I/O Extended,观看 I/O 直播,线下聚会! (3,475)
© 2018 中国谷歌开发者社区 - ChinaGDG