2016年5月22日日曜日

Introducing the Awareness API, an easy way to make your apps context aware - Google I/O 2016

いままで

Where you are
  • Fused Location
  • Places API
  • Geofencing
What you're doing
  • Activity Recognition
  • Google Fit Platform
  • Sensors Platform
What's around you
  • Nearby Messages
  • Nearby Connections
  • Nearby Notifications
それぞれの API を組み合わせて使うのが大変だった。 例えば、複数の条件(Geofencingの中にいて、かつ車に乗っているなど)の組み合わせで処理のトリガーとするのが大変だった。電池への影響も考えないといけない。 そこで、組み合わせて使うのが簡単になる Awareness API をリリースした。

Awareness API

unified sensing platform

7 context types natively supported

  • Location (Latitude and longitude)
  • Places ("Starbucks", Coffee shop)
  • Beacons (What beacons or devices are nearby?)
  • Time (Local time)
  • Activity (Walking, running, biking, or driving)
  • Headphones (Headphones plugged or not?)
  • Weather (Current temperature and conditions)

Fance API

Callback style AreanessFence startDriving = DetectedActivityFence.staring( DetectedActivityFence.IN_VEHICLE); AwarenessFence areaAroundStore = LocationFence.in( STORE_LATITUDE, STORE_LONGITUDE, 1000 /* radius in meters */, 0L /* dwell time */); AwarenessFence duringDriving = DetectedActivityFence.during( DetectedActivityFence.IN_VEHICLE); AwarenessFence openHours = TimeFence.inDailyInterval( TimeZone.getDefault(), 10 * HOURS_IN_MILLIS, 18 * HOURS_IN_MILLIS); AwarenessFence drivingNearStore = AwarenessFence.and( areaAroundStore, duringDriving, openHours); // Create FenceUpdateRequest and register. FenceUdateRequest fenceUpdateRequest = new FenceUpdateRequest.Builder() .addFence("startDriving", startDriving, pendingIntent) .addFence("drivingNearStore", drivingNearStore, pendingIntent) .build(); Awareness.FenceApi.updateFences(googleApiClient, fenceUpdateRequest); void onReceive(Context context, Intent intent) { FenceState fenceState = FenceState.extract(intent); if (fenceState.getFenceKey().equals("startDriving")) { if (fenceSate.getCurrentState() == FenceState.TRUE) { // show map apps } } else if (fenceState.getFenceKey().equals("drivingNearStore")) { if (fenceSate.getCurrentState() == FenceState.TRUE) { // show reminder } } }

Snapshot API

PlacesResult placesResult = Awareness.SnapshotApi.getPlaces(googleApiClient).await(); WeatherResult weatherResult = Awareness.SnapshotApi.getWeather(googleApiClient).await();

Permission

  • Location, Place, Beacon, Weather -> ACCESS_FINE_LOCATION
  • Activity -> ACTIVITY_RECOGNITION
  • Headphones -> no permission

0 件のコメント:

コメントを投稿