Android Open Source - MapAlarmist Geo Alarm Boot Service






From Project

Back to project page MapAlarmist.

License

The source code is released under:

Copyright 2013 Guilhem Vellut <guilhem@vellut.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), t...

If you think the Android project MapAlarmist 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 com.vellut.geoalarm;
//from w w  w  .  j a va  2  s  .c om
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener;
import com.google.android.gms.location.LocationClient;
import com.google.android.gms.location.LocationClient.OnAddGeofencesResultListener;

public class GeoAlarmBootService extends Service implements
    ConnectionCallbacks, OnConnectionFailedListener,
    OnAddGeofencesResultListener {

  private GeoAlarm geoAlarm;
  private LocationClient locationClient;

  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    geoAlarm = new GeoAlarm();
    geoAlarm.restorePreferences(this);
    if (geoAlarm.isAlarmOn) {
      locationClient = new LocationClient(this, this, this);
      locationClient.connect();
    } else {
      stopSelf();
    }

    return START_STICKY;
  }

  @Override
  public IBinder onBind(Intent arg0) {
    // unsupported
    return null;
  }

  @Override
  public void onConnected(Bundle dataBundle) {
    Log.d(GeoAlarmUtils.APPTAG, "Connected to Location Services in service");
    // setup alarm
    try {
      geoAlarm.setAlarm(this, locationClient, this);
      geoAlarm.savePreferences(this);
    } catch (Exception e) {
      Log.e(GeoAlarmUtils.APPTAG, "Error setting alarm", e);
      
    }
  }

  @Override
  public void onDisconnected() {
    stopSelf();
  }

  @Override
  public void onConnectionFailed(ConnectionResult connectionResult) {
    stopSelf();
  }

  @Override
  public void onAddGeofencesResult(int statusCode, String[] geofenceRequestIds) {

    Log.e(GeoAlarmUtils.APPTAG, "Connected to Location Services in service");
    stopSelf();
  }

}




Java Source Code List

com.vellut.geoalarm.AlarmWakeUpBroadcastReceiver.java
com.vellut.geoalarm.AlarmWakeUpService.java
com.vellut.geoalarm.GeoAlarmBootServiceStarter.java
com.vellut.geoalarm.GeoAlarmBootService.java
com.vellut.geoalarm.GeoAlarmUtils.java
com.vellut.geoalarm.GeoAlarm.java
com.vellut.geoalarm.MainActivity.java
com.vellut.geoalarm.ReceiveTransitionsBroadcastReceiver.java
com.vellut.geoalarm.ReceiveTransitionsIntentService.java
com.vellut.geoalarm.SavedLocation.java
com.vellut.geoalarm.SettingsActivity.java
com.vellut.geoalarm.SwipeDismissListViewTouchListener.java
com.vellut.geoalarm.io.LatLngBoundsDeserializer.java
com.vellut.geoalarm.io.LatLngBoundsSerializer.java