{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","params":[],"results":{"codes":[]},"settings":""},"next":{"description":"","pages":[]},"title":"Running the Android Pulsate SDK","type":"basic","slug":"running-the-pulsate-sdk-android","excerpt":"","body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Pulsate Factory\"\n}\n[/block]\nIn order to instantiate the Pulsate Manager you need to use the PulsateFactory. It creates and holds the Pulsate Manager instance, making sure there's only one per application.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \" IPulsateManager manager = PulsateFactory.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:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public class MyApplication extends Application {\\n    private IPulsateManager manager;\\n\\n    :::at:::Override\\n    public void onCreate() {\\n        super.onCreate();\\n    }\\n\\n    public IPulsateManager getPulsate() {\\n        if (manager == null)\\n            manager = PulsateFactory.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 3.0.0 Pulsate.install(this) has been removed. The SDK now installs automatically.\",\n  \"title\": \"Pulsate.install(this)\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Starting Pulsate\"\n}\n[/block]\nThe Pulsate Manager will start the session lifecycle, beacon ranging and geofencing once after you call *startPulsate* on the manager. IPulsateRequestListener can be null.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"manager.startPulsateSession(new IPulsateRequestListener() {\\n  @Override\\n  public void onSucess() {\\n  }\\n\\n  @Override\\n  public void onError(Throwable e) {\\n  }\\n});\",\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 Pulsate.\n\nExamples:\n\n1. If you want to start Pulsate on a specific activity, for example in *\"MainMenuActivity\"*, you should add *\"startPulsateSession()\"* 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()).getPulsate().startPulsateSession(...);\\n    }\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n2. If you want to start Pulsate on a specific action, for example on button click, you should add *\"startPulsateSession()\"* after that action happens, in our case we will add *\"startPulsateSession()\"*  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()).getPulsate().startPulsateSession(...);\\n    }\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"Starting Pulsate\",\n  \"body\": \"Starting Pulsate in the *\\\"onCreate()\\\"* method of your Application class is not supported.\\nPulsate requires an active activity to start.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Starting Pulsate with Location Disabled\"\n}\n[/block]\nTo disable Geofencing and Beacon Scans use the \"*setLocationUpdatesEnabled*\" method\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Disable Location\\nmanager.setLocationUpdatesEnabled(false);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","updates":[],"order":1,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5e5019b49e8f240011cc6a58","parentDoc":null,"project":"54aa7f773b56130b0056c86e","category":{"sync":{"isSync":false,"url":""},"pages":["5e5019b49e8f240011cc6a55","5e5019b49e8f240011cc6a56","5e5019b49e8f240011cc6a57","5e5019b49e8f240011cc6a58","5e5019b49e8f240011cc6a59","5e5019b49e8f240011cc6a5a","5e5019b49e8f240011cc6a5b","5e5019b49e8f240011cc6a5c","5e5019b49e8f240011cc6a5d","5e5019b49e8f240011cc6a5e","5e5019b49e8f240011cc6a68","5e5019b49e8f240011cc6a6b","5e5019b49e8f240011cc6a71","5e5019b49e8f240011cc6a73","5e5019b49e8f240011cc6a7e","5e5019b49e8f240011cc6a80","5e5019b49e8f240011cc6a81","5e5019b49e8f240011cc6a82","5e5019b49e8f240011cc6a84"],"title":"Android SDK","slug":"android-sdk","order":1,"from_sync":false,"reference":false,"_id":"5e5019b49e8f240011cc6a49","version":"5e5019b49e8f240011cc6ade","__v":10,"project":"54aa7f773b56130b0056c86e","createdAt":"2015-01-05T12:44:00.338Z"},"user":"54aa7f3f9bb00c0b00cb899b","createdAt":"2015-01-05T14:11:18.293Z","githubsync":"","version":{"version":"2.8","version_clean":"2.8.0","codename":"Android SDK","is_stable":false,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["5e5019b49e8f240011cc6a47","55781fe35129590d003ff4f9","55781fe35129590d003ff4fa","5e5019b49e8f240011cc6a48","5e5019b49e8f240011cc6a49","5e5019b49e8f240011cc6a4a","5e5019b49e8f240011cc6a4b","5e5019b49e8f240011cc6a4c","565b66c446118c0d00dcb0bb","56898269f8dc340d00308c13","5e5019b49e8f240011cc6a4d","5e5019b49e8f240011cc6a4e","5c73dd27e8fdc000572a206a","5e5019b49e8f240011cc6a4f","5e501b7e7c8bdc00450ea66a","5e53daa9884b750025b5cad4"],"_id":"5e5019b49e8f240011cc6ade","project":"54aa7f773b56130b0056c86e","forked_from":"5e4fbbbda8fb41028f1861fe","__v":2,"createdAt":"2015-06-10T11:30:42.700Z","releaseDate":"2015-06-10T11:30:42.700Z"},"__v":19}

Running the Android Pulsate SDK


[block:api-header] { "type": "basic", "title": "Pulsate Factory" } [/block] In order to instantiate the Pulsate Manager you need to use the PulsateFactory. It creates and holds the Pulsate Manager instance, making sure there's only one per application. [block:code] { "codes": [ { "code": " IPulsateManager manager = PulsateFactory.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:code] { "codes": [ { "code": "public class MyApplication extends Application {\n private IPulsateManager manager;\n\n @Override\n public void onCreate() {\n super.onCreate();\n }\n\n public IPulsateManager getPulsate() {\n if (manager == null)\n manager = PulsateFactory.getInstance();\n return manager;\n }\n}", "language": "java" } ] } [/block] [block:callout] { "type": "danger", "body": "With the release of 3.0.0 Pulsate.install(this) has been removed. The SDK now installs automatically.", "title": "Pulsate.install(this)" } [/block] [block:api-header] { "type": "basic", "title": "Starting Pulsate" } [/block] The Pulsate Manager will start the session lifecycle, beacon ranging and geofencing once after you call *startPulsate* on the manager. IPulsateRequestListener can be null. [block:code] { "codes": [ { "code": "manager.startPulsateSession(new IPulsateRequestListener() {\n @Override\n public void onSucess() {\n }\n\n @Override\n public void onError(Throwable e) {\n }\n});", "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 Pulsate. Examples: 1. If you want to start Pulsate on a specific activity, for example in *"MainMenuActivity"*, you should add *"startPulsateSession()"* 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()).getPulsate().startPulsateSession(...);\n }\n}", "language": "java" } ] } [/block] 2. If you want to start Pulsate on a specific action, for example on button click, you should add *"startPulsateSession()"* after that action happens, in our case we will add *"startPulsateSession()"* 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()).getPulsate().startPulsateSession(...);\n }\n});", "language": "java" } ] } [/block] [block:callout] { "type": "danger", "title": "Starting Pulsate", "body": "Starting Pulsate in the *\"onCreate()\"* method of your Application class is not supported.\nPulsate requires an active activity to start." } [/block] [block:api-header] { "type": "basic", "title": "Starting Pulsate with Location Disabled" } [/block] To disable Geofencing and Beacon Scans use the "*setLocationUpdatesEnabled*" method [block:code] { "codes": [ { "code": "// Disable Location\nmanager.setLocationUpdatesEnabled(false);", "language": "java" } ] } [/block]