{"_id":"59e70b9fe027ae002e7d2f1e","category":{"_id":"59e70b9ee027ae002e7d2ed5","version":"59e70b9ee027ae002e7d2ed2","project":"5496d393f52a630b00519cdd","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-01T13:29:31.291Z","from_sync":false,"order":2,"slug":"android-reference","title":"Android Reference"},"project":"5496d393f52a630b00519cdd","parentDoc":null,"user":"5496d353f52a630b00519cdc","version":{"_id":"59e70b9ee027ae002e7d2ed2","project":"5496d393f52a630b00519cdd","__v":2,"createdAt":"2017-10-18T08:06:54.462Z","releaseDate":"2017-10-18T08:06:54.462Z","categories":["59e70b9ee027ae002e7d2ed3","59e70b9ee027ae002e7d2ed4","59e70b9ee027ae002e7d2ed5","59e70b9ee027ae002e7d2ed6","59e70b9ee027ae002e7d2ed7","59e70b9ee027ae002e7d2ed8","59e70b9ee027ae002e7d2ed9","59e70b9ee027ae002e7d2eda","59e70b9ee027ae002e7d2edb","59e70b9ee027ae002e7d2edc","59e70b9ee027ae002e7d2edd","59e70b9ee027ae002e7d2ede","59e70b9ee027ae002e7d2edf","5b8661ccdd19310003a3fa0b"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"2.0.10","version":"2.0.10"},"githubsync":"","__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-12-01T13:32:47.152Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Activating Geofencing Triggers\"\n}\n[/block]\nActivate geofence triggers in the **placer.properties** file (under the assets directory) by adding the following:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"monitor_geofence = true\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Register your BroadcastReceiver\"\n}\n[/block]\nTo receive geofencing triggers, you need to register your BroadcastReceiver to handle intents named \"com.placer.action.TRIGGER_FIRED\" in the AndroidManifest.xml. The following example shows how to cofigure a BroadcastReceiver named \"MyReceiver\":\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<receiver\\n  \\tandroid:name=\\\"com.example.MyReceiver\\\"\\n    android:enabled=\\\"true\\\"\\n    android:exported=\\\"false\\\">\\n    <intent-filter>\\n        <action android:name=\\\"com.placer.action.TRIGGER_FIRED\\\" />\\n    </intent-filter>\\n</receiver>\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nAll done. Geofence triggers will be sent to your broadcast receiver function. Each intent will contain the following extended string data:\n  * \"id\" - the geofence id, set by customer\n  * \"type\" - either *PLTriggerEvent.TYPE_ENTER* or *PLTriggerEvent.TYPE_EXIT*, specifying whether the mobile device entered the geofence or just left it\n  * \"name\" - customer defined name for the specific geofence object (e.g. \"My Store\")\n  * \"customData\" - key/value map for customer supplied values\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Example\"\n}\n[/block]\nThe following example shows how to handle a geofence trigger with a BroadcastReceiver (named \"MyReceiver\"), and retrieve geofence id, type and assigned name:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"package com.example;\\n\\nimport android.app.NotificationManager;\\nimport android.app.PendingIntent;\\nimport android.content.BroadcastReceiver;\\nimport android.content.Context;\\nimport android.content.Intent;\\nimport android.support.v4.app.NotificationCompat;\\nimport android.util.Log;\\nimport java.util.HashMap;\\n\\npublic class MyReceiver extends BroadcastReceiver {\\n\\n    :::at:::Override\\n    public void onReceive(Context context, Intent intent) {\\n\\n        if (Placer.PLACER_ACTION_NAME_GEOFENCE_TRIGGER.equals(intent.getAction())) {\\n            // Get extra data included in the Intent\\n            PLTriggerEvent plTriggerEvent = intent.getParcelableExtra(Placer.EXTRA_TRIGGER_EVENT);\\n            if(plTriggerEvent != null && plTriggerEvent.getPlGeofence() != null){\\n                // Mandatory fields\\n                Log.d(\\\"onReceive\\\", \\\"Geofence id: \\\" + plTriggerEvent.getPlGeofence().getGeofenceId());\\n                Log.d(\\\"onReceive\\\", \\\"Geofence type: \\\" +(plTriggerEvent.getType() ==PLTriggerEvent.TYPE_ENTER ? \\\"ENTER\\\" : \\\"EXIT\\\"));\\n\\n                // Optional fields, provided by customer\\n                Log.d(\\\"onReceive\\\", \\\"Geofence name: \\\" + plTriggerEvent.getPlGeofence().getName());\\n              \\n                HashMap<String,String> customData = plTriggerEvent.getPlGeofence().getCustomData();\\n            }\\n        }\\n    }\\n}\\n\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"Geofencing allows you to receive triggers in the client.\nTo add geofence POIs please use the designated menu in [our dashboard](https://dashboard.placer.io/#/geofence-custom-pois)","slug":"geofencing-1","type":"basic","title":"Geofencing"}

Geofencing

Geofencing allows you to receive triggers in the client. To add geofence POIs please use the designated menu in [our dashboard](https://dashboard.placer.io/#/geofence-custom-pois)

[block:api-header] { "type": "basic", "title": "Activating Geofencing Triggers" } [/block] Activate geofence triggers in the **placer.properties** file (under the assets directory) by adding the following: [block:code] { "codes": [ { "code": "monitor_geofence = true", "language": "text" } ] } [/block] [block:api-header] { "type": "basic", "title": "Register your BroadcastReceiver" } [/block] To receive geofencing triggers, you need to register your BroadcastReceiver to handle intents named "com.placer.action.TRIGGER_FIRED" in the AndroidManifest.xml. The following example shows how to cofigure a BroadcastReceiver named "MyReceiver": [block:code] { "codes": [ { "code": "<receiver\n \tandroid:name=\"com.example.MyReceiver\"\n android:enabled=\"true\"\n android:exported=\"false\">\n <intent-filter>\n <action android:name=\"com.placer.action.TRIGGER_FIRED\" />\n </intent-filter>\n</receiver>", "language": "java" } ] } [/block] All done. Geofence triggers will be sent to your broadcast receiver function. Each intent will contain the following extended string data: * "id" - the geofence id, set by customer * "type" - either *PLTriggerEvent.TYPE_ENTER* or *PLTriggerEvent.TYPE_EXIT*, specifying whether the mobile device entered the geofence or just left it * "name" - customer defined name for the specific geofence object (e.g. "My Store") * "customData" - key/value map for customer supplied values [block:api-header] { "type": "basic", "title": "Example" } [/block] The following example shows how to handle a geofence trigger with a BroadcastReceiver (named "MyReceiver"), and retrieve geofence id, type and assigned name: [block:code] { "codes": [ { "code": "package com.example;\n\nimport android.app.NotificationManager;\nimport android.app.PendingIntent;\nimport android.content.BroadcastReceiver;\nimport android.content.Context;\nimport android.content.Intent;\nimport android.support.v4.app.NotificationCompat;\nimport android.util.Log;\nimport java.util.HashMap;\n\npublic class MyReceiver extends BroadcastReceiver {\n\n @Override\n public void onReceive(Context context, Intent intent) {\n\n if (Placer.PLACER_ACTION_NAME_GEOFENCE_TRIGGER.equals(intent.getAction())) {\n // Get extra data included in the Intent\n PLTriggerEvent plTriggerEvent = intent.getParcelableExtra(Placer.EXTRA_TRIGGER_EVENT);\n if(plTriggerEvent != null && plTriggerEvent.getPlGeofence() != null){\n // Mandatory fields\n Log.d(\"onReceive\", \"Geofence id: \" + plTriggerEvent.getPlGeofence().getGeofenceId());\n Log.d(\"onReceive\", \"Geofence type: \" +(plTriggerEvent.getType() ==PLTriggerEvent.TYPE_ENTER ? \"ENTER\" : \"EXIT\"));\n\n // Optional fields, provided by customer\n Log.d(\"onReceive\", \"Geofence name: \" + plTriggerEvent.getPlGeofence().getName());\n \n HashMap<String,String> customData = plTriggerEvent.getPlGeofence().getCustomData();\n }\n }\n }\n}\n", "language": "java" } ] } [/block]