Upgrade to Pro — share decks privately, control downloads, hide ads and more …

awareness api

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

awareness api

Avatar for Shinnosuke Kugimiya

Shinnosuke Kugimiya

July 22, 2016
Tweet

More Decks by Shinnosuke Kugimiya

Other Decks in Programming

Transcript

  1. ಋೖ • ैདྷͷGoogle Play ServiceܥͷAPIಋೖํ๏ͱಉ༷ 1. Google Developers ConsoleͰAPIΛ༗ޮʹͯ͠ɺAPI Keyऔಘ

    2. build.gradleͷdependenciesʹ௥Ճ 3. AndroidManifest.xmlʹmeta-dataΛهೖ 4. AndroidManifest.xmlʹඞཁͳPermissionΛ௥Ճ
  2. Current Activity Awareness.SnapshotApi.getDetectedActivity(apiClient) .setResultCallback(new ResultCallback<DetectedActivityResult>() { @Override public void onResult(@NonNull

    DetectedActivityResult detectedActivityResult) { if (!detectedActivityResult.getStatus().isSuccess()) { Log.e(TAG, "Could not get the current activity."); } ActivityRecognitionResult ar = detectedActivityResult.getActivityRecognitionResult(); DetectedActivity probableActivity = ar.getMostProbableActivity(); showActivity(probableActivity); } }); • SnapshotApi.getDetectedActivityΛݺͿ͚ͩ • DetectedActivityResultʹઌͷ৘ใ͕֨ೲ͞Ε͍ͯΔ
  3. Headphone State Awareness.SnapshotApi.getHeadphoneState(apiClient) .setResultCallback(new ResultCallback<HeadphoneStateResult>() { @Override public void onResult(@NonNull

    HeadphoneStateResult headphoneStateResult) { if (!headphoneStateResult.getStatus().isSuccess()) { Log.e(TAG, "Could not get headphone state."); return; } HeadphoneState headphoneState = headphoneStateResult.getHeadphoneState(); showState(headphoneState); } }); • SnapshotApi.getHeadphoneStateΛݺͿ͚ͩ • HeadphoneStateResultʹઌͷ৘ใ͕֨ೲ͞Ε͍ͯΔ
  4. Location Awareness.SnapshotApi.getLocation(apiClient) .setResultCallback(new ResultCallback<LocationResult>() { @Override public void onResult(@NonNull LocationResult

    locationResult) { if (!locationResult.getStatus().isSuccess()) { Log.e(TAG, "Could not get location."); return; } Location location = locationResult.getLocation(); showLocation(location); } }); • SnapshotApi.getLocationΛݺͿ͚ͩ • LocationResultʹઌͷ৘ใ͕֨ೲ͞Ε͍ͯΔ
  5. Nearby Places • ۙ͘ͷࢪઃͷ৘ใ͕औΕΔ w ۙ͘ʹ͋Δࢪઃͷ w ໊લ w ి࿩൪߸

    w Ң౓ܦ౓ w XFCTJUFVSM w SBUJOH w Ձ֨Ϩϕϧ w ͳͲ Awareness APIҎ֎ʹ ผ్ Google Places APIΛ ༗ޮʹ͢Δඞཁ͕͋Δ ͷͰ஫ҙɻ
  6. Nearby Places Awareness.SnapshotApi.getPlaces(apiClient) .setResultCallback(new ResultCallback<PlacesResult>() { @Override public void onResult(@NonNull

    PlacesResult placesResult) { if (!placesResult.getStatus().isSuccess()) { Log.e(TAG, "Could not get places."); return; } showPlaces(placesResult); } }); • SnapshotApi.getPlacesΛݺͿ͚ͩ • PlaceResultʹઌͷ৘ใ͕֨ೲ͞Ε͍ͯΔ
  7. Weather • ఱؾ͕औΕΔ (Լه͕ෳ਺߹Θͬͯ͞औಘͰ͖ Δ) w ΋΍ w פ͍ w

    ཛྷ w շ੖ w ಶΓ w Ӎ w ઇ w ໄ w ෩͕ڧ͍
  8. Weather Awareness.SnapshotApi.getWeather(apiClient) .setResultCallback(new ResultCallback<WeatherResult>() { @Override public void onResult(@NonNull WeatherResult

    weatherResult) { if (!weatherResult.getStatus().isSuccess()) { Log.e(TAG, "Could not get weather."); return; } Weather weather = weatherResult.getWeather(); showWeather(weather); } }); • SnapshotApi.getWeatherΛݺͿ͚ͩ • WeatherResultʹઌͷ৘ใ͕֨ೲ͞Ε͍ͯΔ
  9. どういうFenceを作ることができるのか • Լهͷ৘ใΛऔಘͰ͖Δ w #FBDPO'FODF w %FUFDUFE"DUJWJUZ'FODF w )FBEQIPOF'FODF w

    -PDBUJPO'FODF w 5JNF'FODF • ·ͨ͜ΕΒͷ৘ใΛ૊Έ߹ΘͤΔ͜ͱ΋Մೳ • ྫ͑͹ʮ૸Γग़͔ͨ࣌ͭ͠ϔουϗϯϓϥά͕ϓϥάΠϯঢ়ଶͰ͋ Δʯͱ͍͏ϑΣϯεΛ࡞Δ͜ͱ͕Ͱ͖Δ
  10. Fenceを実際に作る AwarenessFence pluggingIn = HeadphoneFence.pluggingIn(); Awareness.FenceApi.updateFences(mClient, new FenceUpdateRequest.Builder() .addFence(FenceKey.PLUG_IN.name(), pluggingIn,

    mFencePendingIntent).build()) .setResultCallback(new ResultCallback<Status>() { @Override public void onResult(@NonNull Status status) { if (status.isSuccess()) { Log.i(TAG, "fence start updateFences add fence: success"); } else { Log.i(TAG, "fence start updateFences add fence: fail" + status); } } }); • ϔουϗϯͷϓϥάΠϯঢ়ଶʹͳͬͨ࣌ͱ͍ ͏FenceΛ࡞Δ
  11. Fenceを実際に作る AwarenessFence pluggingIn = HeadphoneFence.pluggingIn(); Awareness.FenceApi.updateFences(mClient, new FenceUpdateRequest.Builder() .addFence(FenceKey.PLUG_IN.name(), pluggingIn,

    mFencePendingIntent).build()) .setResultCallback(new ResultCallback<Status>() { @Override public void onResult(@NonNull Status status) { if (status.isSuccess()) { Log.i(TAG, "fence start updateFences add fence: success"); } else { Log.i(TAG, "fence start updateFences add fence: fail" + status); } } }); • Headphone FenceΛऔಘ
  12. Fenceを実際に作る AwarenessFence pluggingIn = HeadphoneFence.pluggingIn(); Awareness.FenceApi.updateFences(mClient, new FenceUpdateRequest.Builder() .addFence(FenceKey.PLUG_IN.name(), pluggingIn,

    mFencePendingIntent).build()) .setResultCallback(new ResultCallback<Status>() { @Override public void onResult(@NonNull Status status) { if (status.isSuccess()) { Log.i(TAG, "fence start updateFences add fence: success"); } else { Log.i(TAG, "fence start updateFences add fence: fail" + status); } } }); • FenceAPI.updateFencesΛݺͿ • ͜Ε͚ͩ
  13. Fenceを登録する • ैདྷͷBroadcast Receiverͱಉ༷ public class FenceReceiver extends BroadcastReceiver {

    private static final String TAG = "FENCE_RECEIVER"; @Override public void onReceive(Context context, Intent intent) { if (!TextUtils.equals("com.kgmyshin.fence.RECEIVE_FENCE", intent.getAction())) { return; } FenceState state = FenceState.extract(intent); if (TextUtils.equals(state.getFenceKey(), FenceKey.PLUG_IN.name())) { if (state.getCurrentState() == FenceState.TRUE) { Toast.makeText(context, "plug in", Toast.LENGTH_SHORT).show(); } Log.i(TAG, "FENCE_START: " + state.getCurrentState()); } } } <receiver android:name=".fence.FenceReceiver"> <intent-filter> <action android:name="com.kgmyshin.fence.RECEIVE_FENCE" /> </intent-filter> </receiver>