Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. public GeofenceTransitionsIntentService(){
  2. super(GeofenceTransitionsIntentService.class.getSimpleName());
  3. }
  4.  
  5. @Override
  6. public void onCreate(){
  7. super.onCreate();
  8. myGoogleApiClient = new GoogleApiClient.Builder(this)
  9. .addApi(LocationServices.API)
  10. .addConnectionCallbacks(this)
  11. .addOnConnectionFailedListener(this)
  12. .build();
  13. }
  14.  
  15. @Override
  16. protected void onHandleIntent(Intent intent) {
  17. GeofencingEvent geoFenceEvent = GeofencingEvent.fromIntent(intent);
  18. if (geoFenceEvent.hasError()){
  19. int errorcode = geoFenceEvent.getErrorCode();
  20. Log.e("GeofencingApp", "ERROR: " + errorcode);
  21. } else {
  22. int transitionType = geoFenceEvent.getGeofenceTransition();
  23.  
  24. if (Geofence.GEOFENCE_TRANSITION_ENTER == transitionType){
  25. myGoogleApiClient.blockingConnect(100, TimeUnit.MILLISECONDS);
  26. String triggeredGeofenceID = geoFenceEvent.getTriggeringGeofences().get(0).getRequestId();
  27.  
  28.  
  29.  
  30.  
  31. } else if (Geofence.GEOFENCE_TRANSITION_EXIT == transitionType) {
  32. myGoogleApiClient.blockingConnect(100, TimeUnit.MILLISECONDS);
  33. String triggeredGeofenceID = geoFenceEvent.getTriggeringGeofences().get(0).getRequestId();
  34. Toast.makeText(getApplicationContext(), "EXIT: " + triggeredGeofenceID, Toast.LENGTH_LONG).show();
  35. }
  36. }
  37. }
  38.  
  39. @Override
  40. public void onConnected(@Nullable Bundle bundle) {
  41.  
  42. }
  43.  
  44. @Override
  45. public void onConnectionSuspended(int i) {
  46.  
  47. }
  48.  
  49. @Override
  50. public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement