{"_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\": \"trigger_notifications_enabled=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  * \"tag\" - the geofence tag data\n  * \"message\" - the geofence push text data\nFor more information about the returned data, please go to [Trigger Response Structure](doc:triggers).\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 generate a local push notification:\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;\\n\\n\\npublic class MyReceiver extends BroadcastReceiver {\\n\\n    //Placer Geofence intent action name\\n    public static final String INTENT_ACTION_TRIGGER_FIRED = \\\"com.placer.action.TRIGGER_FIRED\\\";\\n\\n    public MyReceiver() {\\n    }\\n\\n    :::at:::Override\\n    public void onReceive(Context context, Intent intent) {\\n\\n        if (intent.getAction().equals(INTENT_ACTION_TRIGGER_FIRED)) {\\n\\n            // Get extra data included in the Intent\\n            String tag = intent.getStringExtra(\\\"tag\\\");\\n            String message = intent.getStringExtra(\\\"message\\\");\\n\\n            Log.d(\\\"receiver\\\", \\\"Got message tag: \\\" + tag);\\n\\n            PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);\\n\\n            NotificationCompat.Builder builder = new NotificationCompat.Builder(context)\\n                    .setContentIntent(pi)\\n                    .setAutoCancel(true)\\n                    .setContentTitle(tag)\\n                    .setSmallIcon(R.drawable.ic_launcher)\\n                    .setContentText(message);\\n\\n            NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);\\n            nm.notify(0, builder.build());\\n        } else {\\n            throw new UnsupportedOperationException(\\\"Not yet implemented\\\");\\n        }\\n    }\\n}\\n\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"Geofencing allows you to receive triggers in the client.\nTo learn more about Geofencing and how you can use it, please go to [Geofencing - Getting Started](doc:getting-started-1).","slug":"geofencing-1","type":"basic","title":"Geofencing"}

Geofencing

Geofencing allows you to receive triggers in the client. To learn more about Geofencing and how you can use it, please go to [Geofencing - Getting Started](doc:getting-started-1).

[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": "trigger_notifications_enabled=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: * "tag" - the geofence tag data * "message" - the geofence push text data For more information about the returned data, please go to [Trigger Response Structure](doc:triggers). [block:api-header] { "type": "basic", "title": "Example" } [/block] The following example shows how to handle a geofence trigger with a BroadcastReceiver (named "MyReceiver"), and generate a local push notification: [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;\n\n\npublic class MyReceiver extends BroadcastReceiver {\n\n //Placer Geofence intent action name\n public static final String INTENT_ACTION_TRIGGER_FIRED = \"com.placer.action.TRIGGER_FIRED\";\n\n public MyReceiver() {\n }\n\n @Override\n public void onReceive(Context context, Intent intent) {\n\n if (intent.getAction().equals(INTENT_ACTION_TRIGGER_FIRED)) {\n\n // Get extra data included in the Intent\n String tag = intent.getStringExtra(\"tag\");\n String message = intent.getStringExtra(\"message\");\n\n Log.d(\"receiver\", \"Got message tag: \" + tag);\n\n PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);\n\n NotificationCompat.Builder builder = new NotificationCompat.Builder(context)\n .setContentIntent(pi)\n .setAutoCancel(true)\n .setContentTitle(tag)\n .setSmallIcon(R.drawable.ic_launcher)\n .setContentText(message);\n\n NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);\n nm.notify(0, builder.build());\n } else {\n throw new UnsupportedOperationException(\"Not yet implemented\");\n }\n }\n}\n", "language": "java" } ] } [/block]