Java Code Examples for com.google.android.gms.awareness.fence.FenceUpdateRequest#Builder
The following examples show how to use
com.google.android.gms.awareness.fence.FenceUpdateRequest#Builder .
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: GapiFenceManager.java From JCVD with MIT License | 6 votes |
/** * Add a fence to the Google API * If not connected, this will only trigger a connection. * This call requires that the following granted permissions: * - ACCESS_FINE_LOCATION if one of the fence is a {@link StorableLocationFence} * - ACTIVITY_RECOGNITION if one of the fence is a {@link StorableActivityFence} * @param id the unique id of the fence. * @param fence the fence to store * @param pendingIntentClassName the class name of the pending intent to call when the fence will be valid. * @param status the status that will be called when the addition fails or succeed. * @return true if add has been asked, false otherwise. */ boolean addFence(@NonNull String id, @NonNull AwarenessFence fence, @NonNull String pendingIntentClassName, @Nullable final ResultCallback<Status> status) { FenceUpdateRequest.Builder requestBuilder = new FenceUpdateRequest.Builder() .addFence(id, fence, createRequestPendingIntent(pendingIntentClassName)); mFenceClient.updateFences(requestBuilder.build()) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (status != null) { if (task.isSuccessful()) { status.onResult(Status.RESULT_SUCCESS); } else { status.onResult(Status.RESULT_INTERNAL_ERROR); } } } }); return true; }
Example 2
Source File: GapiFenceManager.java From JCVD with MIT License | 6 votes |
/** * Ask to remove a fence from the Google API. * @param fenceId The id of the fence to remove. * @param status the status that will be called when the addition fails or succeed. * @return true if remove has been asked, false otherwise. */ boolean removeFence(@NonNull String fenceId, final ResultCallback<Status> status) { FenceUpdateRequest.Builder requestBuilder = new FenceUpdateRequest.Builder() .removeFence(fenceId); mFenceClient.updateFences(requestBuilder.build()).addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { status.onResult(Status.RESULT_SUCCESS); } else { status.onResult(Status.RESULT_INTERNAL_ERROR); } } }); return true; }
Example 3
Source File: MainActivity.java From AndroidDemoProjects with Apache License 2.0 | 4 votes |
private void createFence() { checkLocationPermission(); AwarenessFence activityFence = DetectedActivityFence.during(DetectedActivityFence.STILL); AwarenessFence homeFence = LocationFence.in(39.92, -105.7, 100000, 1000 ); AwarenessFence sittingAtHomeFence = AwarenessFence.and(homeFence, activityFence); Intent intent = new Intent(ACTION_FENCE); PendingIntent fencePendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); mFenceBroadcastReceiver = new FenceBroadcastReceiver(); registerReceiver(mFenceBroadcastReceiver, new IntentFilter(ACTION_FENCE)); FenceUpdateRequest.Builder builder = new FenceUpdateRequest.Builder(); builder.addFence(KEY_SITTING_AT_HOME, sittingAtHomeFence, fencePendingIntent); Awareness.FenceApi.updateFences( mGoogleApiClient, builder.build() ); }