Android Open Source - Toury-Glass Receive Transitions Intent Service






From Project

Back to project page Toury-Glass.

License

The source code is released under:

MIT License

If you think the Android project Toury-Glass listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package twilight.of.the.devs.touryglass;
/* w w w  . ja va2s.  c  o  m*/
import java.util.List;

import com.google.android.gms.location.Geofence;
import com.google.android.gms.location.LocationClient;

import android.app.IntentService;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.widget.Toast;

public class ReceiveTransitionsIntentService extends IntentService {

  private static final String TAG = ReceiveTransitionsIntentService.class.getName();

  public ReceiveTransitionsIntentService() {
    super("TransitionReceiever");
  }

  @Override
  protected void onHandleIntent(Intent intent) {
    // First check for errors
        if (LocationClient.hasError(intent)) {
            // Get the error code with a static method
            int errorCode = LocationClient.getErrorCode(intent);
            // Log the error
            Log.e("ReceiveTransitionsIntentService",
                    "Location Services error: " +
                    Integer.toString(errorCode));
            /*
             * You can also send the error code to an Activity or
             * Fragment with a broadcast Intent
             */
        /*
         * If there's no error, get the transition type and the IDs
         * of the geofence or geofences that triggered the transition
         */
        } else {
            // Get the type of transition (entry or exit)
            int transitionType =
                    LocationClient.getGeofenceTransition(intent);
            // Test that a valid transition was reported
            if (
                (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER)
                 ||
                (transitionType == Geofence.GEOFENCE_TRANSITION_EXIT)
                ||
                (transitionType == Geofence.GEOFENCE_TRANSITION_DWELL)
               ) {
                List <Geofence> triggerList =
                        LocationClient.getTriggeringGeofences(intent);

                String[] triggerIds = new String[triggerList.size()];

                for (int i = 0; i < triggerIds.length; i++) {
                    // Store the Id of each geofence
                    triggerIds[i] = triggerList.get(i).getRequestId();
                }
                Geofence g = triggerList.get(0);
                
                Intent i = new Intent("location");
                i.putExtra("loc", triggerList.get(0).toString());
                LocalBroadcastManager.getInstance(this).sendBroadcast(i);
                
            }
        // An invalid transition was reported
        } 
  }

}




Java Source Code List

twilight.of.the.devs.touryglass.Callback.java
twilight.of.the.devs.touryglass.LiveCardRenderer.java
twilight.of.the.devs.touryglass.LocationHandler.java
twilight.of.the.devs.touryglass.MainActivity.java
twilight.of.the.devs.touryglass.ReceiveTransitionsIntentService.java
twilight.of.the.devs.touryglass.ServerThread.java
twilight.of.the.devs.touryglass.SyncService.java
twilight.of.the.devs.touryglass.TestActivity.java
twilight.of.the.devs.touryglass.TouryREST.java
twilight.of.the.devs.touryglass.TouryService.java
twilight.of.the.devs.touryglass.TouryView.java
twilight.of.the.devs.touryglass.provider.TouryProvider.java
twilight.of.the.devs.utils.DirectionUtils.java
twilight.of.the.devs.utils.GeofenceManager.java
twilight.of.the.devs.utils.MathUtils.java
twilight.of.the.devs.utils.OrientationManager.java