{"_id":"58aad9dd8f862f250076fa00","__v":0,"user":"54aa7f3f9bb00c0b00cb899b","version":{"_id":"58aad9dd8f862f250076f9f4","project":"54aa7f773b56130b0056c86e","__v":2,"createdAt":"2017-02-20T11:58:21.765Z","releaseDate":"2017-02-20T11:58:21.765Z","categories":["58aad9dd8f862f250076f9f5","58aad9dd8f862f250076f9f6","58aad9dd8f862f250076f9f7","58aad9dd8f862f250076f9f8","58aad9dd8f862f250076f9f9","58aad9dd8f862f250076f9fa","58aad9dd8f862f250076f9fb","58ac26b3d460ce2500185d26"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":false,"codename":"Locate","version_clean":"6.0.0","version":"6.0"},"parentDoc":null,"category":{"_id":"58aad9dd8f862f250076f9f8","project":"54aa7f773b56130b0056c86e","version":"58aad9dd8f862f250076f9f4","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-01-05T12:44:00.338Z","from_sync":false,"order":4,"slug":"android-sdk","title":"Android SDK"},"project":"54aa7f773b56130b0056c86e","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-01-05T14:11:18.293Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Locate Factory\"\n}\n[/block]\nIn order to instantiate the Locate Manager you need to use the LocateFactory. It creates and holds the Locate Manager instance, making sure there's only one per application.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \" ILocateManager manager = LocateFactory.getInstance();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nWe recommend to create a method in your App class which will hold the instance and create one if it doesnt exist.\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"Initialize IPulsateManager\",\n  \"body\": \"Please remember to initialize the ILocateManager in your application \\\"onCreate()\\\" method.\\nTo initilize use - LocateFactory.getInstance();\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public class MyApplication extends Application {\\n\\n    ILocateManager manager;\\n\\n    :::at:::Override\\n    public void onCreate() {\\n        super.onCreate();\\n      \\tLocate.install(this);\\n\\t\\t\\t\\tgetLocate();\\n    }\\n\\n    public ILocateManager getLocate() {\\n        if (manager == null)\\n            manager = LocateFactory.getInstance();\\n        return manager;\\n    }\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"body\": \"With the release of 2.9.2 LocateApp has been deprecated. Please use Locate.install(this); in your Application's onCreate method to properly install Locate.\",\n  \"title\": \"LocateApp\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Starting Locate\"\n}\n[/block]\nThe Locate Manager will start the session lifecycle, beacon ranging and geofencing once after you call *startLocate* on the manager.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"manager.startLocateSession();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nIf you keep the manager in your application class as presented above, you have easy access to the manager from anywhere in your app and you can easily start Locate.\n\nExamples:\n\n1. If you want to start Locate on a specific activity, for example in *\"MainMenuActivity\"*, you should add *\"startLocateSession()\"* in the *\"onCreate()\"* method of your Activity class.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public class MainMenuActivity extends Activity {\\n    @Override\\n    protected void onCreate(Bundle savedInstanceState) {\\n        super.onCreate(savedInstanceState);\\n        setContentView(R.layout.activity_main_menu);\\n        ((MyApplication) getApplication()).getLocate().startLocateSession();\\n    }\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n2. If you want to start Locate on a specific action, for example on button click, you should add *\"startLocateSession()\"* after that action happens, in our case we will add *\"startLocateSession()\"*  in the the *\"onClick()\"* method of our *\"OnClickListener\"*.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Button myButton = (Button) findViewById(R.id.my_button);\\nmyButton.setOnClickListener(new View.OnClickListener() {\\n    @Override\\n    public void onClick(View view) {\\n        ((MyApplication) getApplication()).getLocate().startLocateSession();\\n    }\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"Starting Locate\",\n  \"body\": \"Starting Locate in the *\\\"onCreate()\\\"* method of your Application class is not supported.\\nLocate requires an active activity to start.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Starting Locate with Beacon Ranging Disabled\"\n}\n[/block]\nWith the release of version 2.1.1 of the Locate SDK you can also start Locate with beacon ranging disabled.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"Use *\\\"startLocateSessionWithBeaconsDisabled\\\"* instead of *\\\"startLocateSession\\\"*.\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"manager.startLocateSessionWithBeaconsDisabled();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Starting Locate with Location Disabled\"\n}\n[/block]\nWith the release of version 2.7.10 of the Locate SDK you can also enable or disable location.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"manager.setGpsManagerEnabled(boolean enabled);\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"running-the-pulsate-sdk-android","type":"basic","title":"Running the Locate SDK"}

Running the Locate SDK


[block:api-header] { "type": "basic", "title": "Locate Factory" } [/block] In order to instantiate the Locate Manager you need to use the LocateFactory. It creates and holds the Locate Manager instance, making sure there's only one per application. [block:code] { "codes": [ { "code": " ILocateManager manager = LocateFactory.getInstance();", "language": "java" } ] } [/block] We recommend to create a method in your App class which will hold the instance and create one if it doesnt exist. [block:callout] { "type": "danger", "title": "Initialize IPulsateManager", "body": "Please remember to initialize the ILocateManager in your application \"onCreate()\" method.\nTo initilize use - LocateFactory.getInstance();" } [/block] [block:code] { "codes": [ { "code": "public class MyApplication extends Application {\n\n ILocateManager manager;\n\n @Override\n public void onCreate() {\n super.onCreate();\n \tLocate.install(this);\n\t\t\t\tgetLocate();\n }\n\n public ILocateManager getLocate() {\n if (manager == null)\n manager = LocateFactory.getInstance();\n return manager;\n }\n}", "language": "java" } ] } [/block] [block:callout] { "type": "danger", "body": "With the release of 2.9.2 LocateApp has been deprecated. Please use Locate.install(this); in your Application's onCreate method to properly install Locate.", "title": "LocateApp" } [/block] [block:api-header] { "type": "basic", "title": "Starting Locate" } [/block] The Locate Manager will start the session lifecycle, beacon ranging and geofencing once after you call *startLocate* on the manager. [block:code] { "codes": [ { "code": "manager.startLocateSession();", "language": "java" } ] } [/block] If you keep the manager in your application class as presented above, you have easy access to the manager from anywhere in your app and you can easily start Locate. Examples: 1. If you want to start Locate on a specific activity, for example in *"MainMenuActivity"*, you should add *"startLocateSession()"* in the *"onCreate()"* method of your Activity class. [block:code] { "codes": [ { "code": "public class MainMenuActivity extends Activity {\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_main_menu);\n ((MyApplication) getApplication()).getLocate().startLocateSession();\n }\n}", "language": "java" } ] } [/block] 2. If you want to start Locate on a specific action, for example on button click, you should add *"startLocateSession()"* after that action happens, in our case we will add *"startLocateSession()"* in the the *"onClick()"* method of our *"OnClickListener"*. [block:code] { "codes": [ { "code": "Button myButton = (Button) findViewById(R.id.my_button);\nmyButton.setOnClickListener(new View.OnClickListener() {\n @Override\n public void onClick(View view) {\n ((MyApplication) getApplication()).getLocate().startLocateSession();\n }\n});", "language": "java" } ] } [/block] [block:callout] { "type": "danger", "title": "Starting Locate", "body": "Starting Locate in the *\"onCreate()\"* method of your Application class is not supported.\nLocate requires an active activity to start." } [/block] [block:api-header] { "type": "basic", "title": "Starting Locate with Beacon Ranging Disabled" } [/block] With the release of version 2.1.1 of the Locate SDK you can also start Locate with beacon ranging disabled. [block:callout] { "type": "warning", "body": "Use *\"startLocateSessionWithBeaconsDisabled\"* instead of *\"startLocateSession\"*." } [/block] [block:code] { "codes": [ { "code": "manager.startLocateSessionWithBeaconsDisabled();", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "Starting Locate with Location Disabled" } [/block] With the release of version 2.7.10 of the Locate SDK you can also enable or disable location. [block:code] { "codes": [ { "code": "manager.setGpsManagerEnabled(boolean enabled);", "language": "text" } ] } [/block]