Skip to content

nicomagni/Novocation

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Novocation

Novocation is a project to hide Android location logic away in a jar. Most of the code originates from Reto Meier’s Android Protips: A Deep Dive Into Location. It’s also heaviliy inspired by Stefano Dacchille’s Ignition Location.

Please report bugs, tell us about your problems or request features by creating issues here on GitHub.

Demo app

If you want to see the capabilities of the library you can try out the Novocation demo. This will also help us in improving the library as we track with analytics the quality of the position and the time to get it.

How to use the library

Using maven

If you are using maven you need to define the repo and then the dependency

<repositories>
  <repository>
    <id>public-mvn-repo-releases</id>
    <url>https://github.com/novoda/public-mvn-repo/raw/master/releases</url>
  </repository>
</repositories>
<dependency>
  <groupId>com.novoda.location</groupId>
  <artifactId>novocation-core</artifactId>
  <version>1.0.3</version>
</dependency>

Direct jar usage

If you don’t care about building tool you can just download the jar manually from this link

download jar

Implementation

Application

In the application you can keep a reference to the locator in this way :


  @Override
  public void onCreate() {
    super.onCreate();
    LocatorSettings settings = new LocatorSettings(PACKAGE_NAME, LOCATION_UPDATE_ACTION);
    settings.setUpdatesInterval(3 * 60 * 1000);
    settings.setUpdatesDistance(50);
    locator = LocatorFactory.getInstance();
    locator.prepare(getApplicationContext(), settings);
  }

In the Activity using the location

You need to to start the locator in the onResume and stop it in the onPause method. Something similar to:


@Override
public void onResume() {
  super.onResume();
  IntentFilter f = new IntentFilter();
  f.addAction(LocationDemo.LOCATION_UPDATE_ACTION);
  registerReceiver(freshLocationReceiver, f);
  try {
    locator.startLocationUpdates();
  } catch(NoProviderAvailable np) {
    //TODO add implementation
  }
}

@Override
public void onPause() {
  unregisterReceiver(freshLocationReceiver);
  locator.stopLocationUpdates();
  super.onPause();
}

public BroadcastReceiver freshLocationReceiver = new BroadcastReceiver() {
   @Override
   public void onReceive(Context context, Intent intent) {
      locator.getLocation();
   }
};

Manifest


<receiver android:name="com.novoda.location.receiver.LocationChanged">
  <intent-filter>
    <action android:name="com.novoda.location.ACTIVE_LOCATION_UPDATE_ACTION"/>
  </intent-filter>
</receiver>

<receiver android:name="com.novoda.location.receiver.PassiveLocationChanged"/>

<receiver android:name="com.novoda.location.receiver.UnregisterPassiveListenerOnLostConnectivity" enabled="false">
  <intent-filter>
    <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
  </intent-filter>
</receiver>

<receiver android:name="com.novoda.location.receiver.UnregisterPassiveListenerOnLowBattery">
  <intent-filter>
    <action android:name="android.intent.action.BATTERY_LOW"/>
    <action android:name="android.intent.action.BATTERY_OKAY"/>
  </intent-filter>
</receiver>

<receiver android:name="com.novoda.location.receiver.RestorePassiveListenerBoot">
  <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED"/>
  </intent-filter>
</receiver>

License

Novocation is licensed under the Apache License 2.0.

About

An attempt jar-ify location.

Resources

License

Stars

Watchers

Forks

Packages

No packages published