Java Code Examples for com.google.android.gms.awareness.fence.HeadphoneFence#pluggingIn()
The following examples show how to use
com.google.android.gms.awareness.fence.HeadphoneFence#pluggingIn() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StorableHeadphoneFence.java From JCVD with MIT License | 5 votes |
@Override AwarenessFence getAwarenessFence(Context ctx) { switch (mTriggerType) { case STATE: return HeadphoneFence.during(mHeadphoneState); case PLUGGING_IN: return HeadphoneFence.pluggingIn(); case UNPLUGGING: return HeadphoneFence.unplugging(); } return null; }
Example 2
Source File: MainActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 4 votes |
private void listing15_29_30_31_32() { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } int flags = PendingIntent.FLAG_UPDATE_CURRENT; Intent intent = new Intent(this, WalkFenceReceiver.class); PendingIntent awarenessIntent = PendingIntent.getBroadcast(this, -1, intent, flags); // Listing 15-29: Creating Awareness Fences // Near one of my custom beacons. BeaconState.TypeFilter typeFilter = BeaconState.TypeFilter.with("com.professionalandroid.apps.beacon", "my_type"); AwarenessFence beaconFence = BeaconFence.near(typeFilter); // While walking. AwarenessFence activityFence = DetectedActivityFence.during(DetectedActivityFence.WALKING); // Having just plugged in my headphones. AwarenessFence headphoneFence = HeadphoneFence.pluggingIn(); // Within 1km of Google for longer than a minute. double lat = 37.4220233; double lng = -122.084252; double radius = 1000; // meters long dwell = 60000; // milliseconds. AwarenessFence locationFence = LocationFence.in(lat, lng, radius, dwell); // In the morning AwarenessFence timeFence = TimeFence.inTimeInterval(TimeFence.TIME_INTERVAL_MORNING); // During holidays AwarenessFence holidayFence = TimeFence.inTimeInterval(TimeFence.TIME_INTERVAL_HOLIDAY); // Listing 15-30: Combining Awareness Fences // Trigger when headphones are plugged in and walking in the morning // either within a kilometer of Google or near one of my beacons -- // but not on a holiday. AwarenessFence morningWalk = AwarenessFence .and(activityFence, headphoneFence, timeFence, AwarenessFence.or(locationFence, beaconFence), AwarenessFence.not(holidayFence)); // Listing 15-31: Creating an Awareness Fence Update Request FenceUpdateRequest fenceUpdateRequest = new FenceUpdateRequest.Builder() .addFence(WalkFenceReceiver.WALK_FENCE_KEY, morningWalk, awarenessIntent) .build(); // Listing 15-32: Adding a new Awareness Fence Awareness.FenceApi.updateFences( mGoogleApiClient, fenceUpdateRequest).setResultCallback(new ResultCallback<Status>() { @Override public void onResult(@NonNull Status status) { if (!status.isSuccess()) { Log.d(TAG, "Fence could not be registered: " + status); } } }); }