DE

EgiGeoZone

EgiGeoZone Forum

Download

 

This section is intended for developers

Develop a plugin for EgiGeoZone

Starting from version 2.0.4, EgiGeoZone introduced the ability to handle plugins. Here is a short description how to make such a plugin.

Recipe to develop a EgiGeoZone plugin

- First, create a new Android project and then create at least one Activity for the plug-in configuration. The plugin itself is responsible for saving the configuration. You can, for example, save the configuration in the SharedPreferences or in your database.

- The project must also create a BroadcastReceiver or better a WakefulBroadcastReceiver which will receive an Intent. The BroadcastReceiver needs to listen to the action "de.egi.geofence.geozone.plugin.EVENT". The best choice is that the BroadcastReceiver will start a service, which then does the plugin work.

- The EgiGeoZone app Intent provides the following parameters to the plugins:

  • "transition": "1" for entering and "0" for leaving the zone
  • "zone_name": Name of the zone
  • "latitude": latitude of the zone
  • "longitude": longitude zone
  • "device_id": An UUID, which is supposed to represent the ID of the mobile device
  • "date_iso": UTC date and time in the format "yyyy-MM-dd'T'HH: mm: ss'Z '"
  • "date_device": Local date and time in the format "yyyy-MM-dd'T'HH: mm: ss"

If available to the main app, new parameters can be requested.

- Once an EgiGeoZone event is about to broadcast to the plugins, then the EgiGeoZone app checks, if the plugins have an Intent-Filter with an action "de.egi.geofence.geozone.GETPLUGINS". Only to this plugins the app will broadcast his Intent.

Example of this part in the manifest file:

    <activity
        android:name=".ExamplePluginMain"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <action android:name="de.egi.geofence.geozone.GETPLUGINS" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

- Also you need the following permission, which keeps the processor from sleeping when a message is received in the Broadcastreceiver:
<uses-permission android:name="android.permission.WAKE_LOCK" />

- Under the Administration menu the EgiGeoZone app shows a list of the found plugins on the device. With a tap on one of the plugins, the main activity of the plugin can be invoked. So it is a good idea to have the application label and application icon referenced in the manifest file:

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    ...

- Again: the receiver of the plugin needs to listen to the action "de.egi.geofence.geozone.plugin.EVENT":

    <receiver android:name=".ExampleBroadcastReceiverPlugin">
        <intent-filter>
            <action android:name="de.egi.geofence.geozone.plugin.EVENT" />
        </intent-filter>
    </receiver>

- (10.03.2017) You can now retrieve the names of the defined zones from the main app from the plugins. For this I have included in the apps a ContentProvider.
But since there are two apps an EgiGeoZone and an EgiGeoZoneBT, both variants should be available in the plugin. The difference is an additional ".bt" in the package name.

Plugin for EgiGeoZone:

private static final Uri CONTENT_URI = Uri.parse("content://de.egi.geofence.geozone.zonesContentProvider/zoneNames");

Example:
    private static final Uri CONTENT_URI = Uri.parse("content://de.egi.geofence.geozone.zonesContentProvider/zoneNames");
    private static final String CN_NAME = "name";
....
        // Returns the zone names. You may not select other fields or make changes on them
        ContentResolver cr = this.getContentResolver();
        Cursor cursor = cr.query(CONTENT_URI, null, null, null, null);

        if (cursor.moveToFirst()) {
            do{
                Toast.makeText(this, cursor.getString(cursor.getColumnIndex(CN_NAME)), Toast.LENGTH_SHORT).show();
            } while (cursor.moveToNext());
        }

Plugin for EgiGeoZoneBT:

private static final Uri CONTENT_URI = Uri.parse("content://de.egi.geofence.geozone.bt.zonesContentProvider/zoneNames");
 
Example:
    private static final Uri CONTENT_URI = Uri.parse("content://de.egi.geofence.geozone.bt.zonesContentProvider/zoneNames");
    private static final String CN_NAME = "name";
....
        // Returns the zone names. You may not select other fields or make changes on them
        ContentResolver cr = this.getContentResolver();
        Cursor cursor = cr.query(CONTENT_URI, null, null, null, null);

        if (cursor.moveToFirst()) {
            do{
                Toast.makeText(this, cursor.getString(cursor.getColumnIndex(CN_NAME)), Toast.LENGTH_SHORT).show();
            } while (cursor.moveToNext());
        }
 

- An example plugin source code can be downloaded here: ExamplePluginSource.zip
  This plugin shows only a notification on the devicem when an event occured in the main app.

- The example plugin may also be installed from the Google Play Store: ExamplePlugin

Keep in mind to check "Allow broadcasting to plugins" in the Adminstration section in the main app.