Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public GeofenceTransitionsIntentService(){
- super(GeofenceTransitionsIntentService.class.getSimpleName());
- }
- @Override
- public void onCreate(){
- super.onCreate();
- myGoogleApiClient = new GoogleApiClient.Builder(this)
- .addApi(LocationServices.API)
- .addConnectionCallbacks(this)
- .addOnConnectionFailedListener(this)
- .build();
- }
- @Override
- protected void onHandleIntent(Intent intent) {
- GeofencingEvent geoFenceEvent = GeofencingEvent.fromIntent(intent);
- if (geoFenceEvent.hasError()){
- int errorcode = geoFenceEvent.getErrorCode();
- Log.e("GeofencingApp", "ERROR: " + errorcode);
- } else {
- int transitionType = geoFenceEvent.getGeofenceTransition();
- if (Geofence.GEOFENCE_TRANSITION_ENTER == transitionType){
- myGoogleApiClient.blockingConnect(100, TimeUnit.MILLISECONDS);
- String triggeredGeofenceID = geoFenceEvent.getTriggeringGeofences().get(0).getRequestId();
- } else if (Geofence.GEOFENCE_TRANSITION_EXIT == transitionType) {
- myGoogleApiClient.blockingConnect(100, TimeUnit.MILLISECONDS);
- String triggeredGeofenceID = geoFenceEvent.getTriggeringGeofences().get(0).getRequestId();
- Toast.makeText(getApplicationContext(), "EXIT: " + triggeredGeofenceID, Toast.LENGTH_LONG).show();
- }
- }
- }
- @Override
- public void onConnected(@Nullable Bundle bundle) {
- }
- @Override
- public void onConnectionSuspended(int i) {
- }
- @Override
- public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement