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
  1. AreanessFence startDriving = DetectedActivityFence.staring(  
  2.  DetectedActivityFence.IN_VEHICLE);  
  3.   
  4. AwarenessFence areaAroundStore = LocationFence.in(  
  5.  STORE_LATITUDE, STORE_LONGITUDE,  
  6.  1000 /* radius in meters */, 0L /* dwell time */);  
  7.   
  8. AwarenessFence duringDriving = DetectedActivityFence.during(  
  9.  DetectedActivityFence.IN_VEHICLE);  
  10.   
  11. AwarenessFence openHours = TimeFence.inDailyInterval(  
  12.  TimeZone.getDefault(),  
  13.  10 * HOURS_IN_MILLIS,  
  14.  18 * HOURS_IN_MILLIS);  
  15.   
  16. AwarenessFence drivingNearStore = AwarenessFence.and(  
  17.     areaAroundStore,  
  18.     duringDriving,  
  19.     openHours);  
  20.   
  21. // Create FenceUpdateRequest and register.  
  22. FenceUdateRequest fenceUpdateRequest = new FenceUpdateRequest.Builder()  
  23.  .addFence("startDriving", startDriving, pendingIntent)  
  24.  .addFence("drivingNearStore", drivingNearStore, pendingIntent)  
  25.  .build();  
  26.   
  27. Awareness.FenceApi.updateFences(googleApiClient, fenceUpdateRequest);  
  1. void onReceive(Context context, Intent intent) {  
  2.  FenceState fenceState = FenceState.extract(intent);  
  3.  if (fenceState.getFenceKey().equals("startDriving")) {  
  4.    if (fenceSate.getCurrentState() == FenceState.TRUE) {  
  5.        // show map apps  
  6.    }  
  7.  } else if (fenceState.getFenceKey().equals("drivingNearStore")) {  
  8.    if (fenceSate.getCurrentState() == FenceState.TRUE) {  
  9.        // show reminder  
  10.    }  
  11.  }  
  12. }  

Snapshot API

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

Permission

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

0 件のコメント:

コメントを投稿