{"__v":35,"_id":"55ac917b5863b817008ae3b4","category":{"__v":15,"_id":"5540e5f131827a0d007ab212","pages":["5540e66b31827a0d007ab217","5540e67731827a0d007ab219","55ac917b5863b817008ae3b4","55acaa4c6b4ff90d00784a92","55acb96418eefd0d0071d553","55acc8aa18eefd0d0071d596","55accd2818eefd0d0071d5a8","55acd06518eefd0d0071d5b6","55acddd7fb7b3c19003739cc","55ace14bfb7b3c19003739d3","55ace3a9fb7b3c19003739d7","55acea24f93f0c0d005b880f","55acf15bf93f0c0d005b8821","55acf3cd18eefd0d0071d5fb","55d1f1c0486de50d00326f17"],"project":"5540ce1b31827a0d007ab1cc","version":"5540ce1c31827a0d007ab1cf","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-04-29T14:08:49.271Z","from_sync":false,"order":4,"slug":"android","title":"Android"},"parentDoc":null,"project":"5540ce1b31827a0d007ab1cc","user":"55a79a4d4a33f92b00b7a111","version":{"__v":31,"_id":"5540ce1c31827a0d007ab1cf","project":"5540ce1b31827a0d007ab1cc","createdAt":"2015-04-29T12:27:08.390Z","releaseDate":"2015-04-29T12:27:08.390Z","categories":["5540ce1c31827a0d007ab1d0","5540d91bbb9e762d00f594ad","5540e5f131827a0d007ab212","5540e5febb9e762d00f594d3","5540e61331827a0d007ab213","5540e6195cf9682100d61afa","5540e62631827a0d007ab214","5540e63031827a0d007ab215","5540e63531827a0d007ab216","5540e63e5cf9682100d61afc","5540e6445cf9682100d61afd","5540e64a5cf9682100d61afe","55a4ff5b2e70c0250038050f","55acb28318eefd0d0071d504","55ae1abe8576b92300291c80","55ae453ef302af23000ac109","55af586d555b900d0036d296","55af91dac8a85321007a53c3","55b9fee204775a2f00628071","55b9ff0e04775a2f00628072","55b9ff4604775a2f00628073","55b9ff5fd72d1e1900276a38","55b9ff7f04775a2f00628074","55b9ff90eb08801900f833e5","55b9ffa5d72d1e1900276a39","55b9ffca04775a2f00628075","55b9fffdd72d1e1900276a3a","56bc2f033ee9e70d008b46af","56c2f6efbbf9ec2d00e0fe4f","57595bbb18760817001e8bbe","57d8d9793916800e003dde53"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-07-20T06:13:15.516Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"[**Download SDK**](https://github.com/Pushwoosh/pushwoosh-android-sdk)\n[**Sample Project**](https://github.com/Pushwoosh/pushwoosh-android-sdk/tree/master/Samples/Android-Simple)\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"This Android SDK integration guide uses Fragments.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Gradle integration\"\n}\n[/block]\n*Replace \"+\" with current version of Pushwoosh, Android Support and Google Play Services libraries* \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"compile 'com.pushwoosh:pushwoosh:+'\\ncompile 'com.android.support:support-v4:+'\\ncompile 'com.google.android.gms:play-services-gcm:+'\\ncompile 'com.google.android.gms:play-services-location:+'\",\n      \"language\": \"groovy\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Writing code\"\n}\n[/block]\n**1**. In AndroidManifest.xml manifest add the following lines under application tag:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<meta-data android:name=\\\"PW_APPID\\\" android:value=\\\"XXXXX-XXXXX\\\" />\\n<meta-data android:name=\\\"PW_PROJECT_ID\\\" android:value=\\\"A123456789012\\\" />\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\nWhere:\n*PW_APPID* is your Pushwoosh Application Code\n*PW_PROJECT_ID* is the *Project Number* you received from Google ([Locate your Project Number](http://docs.pushwoosh.com/docs/android-faq#how-to-locate-my-google-project-number)), prefixed with A.\n\n**2.** Extend your Main activity from the **FragmentActivity** class and implement **PushEventListener** interface:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public class PushFragmentActivity extends FragmentActivity implements PushEventListener\\n\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n**3.** In onCreate function call `PushFragment.init(this);`\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \":::at:::Override\\nprotected void onCreate(Bundle savedInstanceState)\\n{\\n    super.onCreate(savedInstanceState);\\n \\n    //Init Pushwoosh fragment\\n    PushFragment.init(this);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n**4.** In onNewIntent function call `PushFragment.onNewIntent(this, intent);`\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@Override\\npublic void onNewIntent(Intent intent)\\n{\\n    super.onNewIntent(intent);\\n \\n    //Check if we've got new intent with a push notification\\n    PushFragment.onNewIntent(this, intent);\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n**5.** Implement callbacks as per **PushEventListener** interface:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@Override\\npublic void doOnRegistered(String registrationId)\\n{\\n    Log.i(TAG, \\\"Registered for pushes: \\\" + registrationId);\\n}\\n\\n@Override\\npublic void doOnRegisteredError(String errorId)\\n{\\n    Log.e(TAG, \\\"Failed to register for pushes: \\\" + errorId);\\n}\\n\\n@Override\\npublic void doOnMessageReceive(String message)\\n{\\n    Log.i(TAG, \\\"Notification opened: \\\" + message);\\n}\\n\\n@Override\\npublic void doOnUnregistered(final String message)\\n{\\n    Log.i(TAG, \\\"Unregistered from pushes: \\\" + message);\\n}\\n\\n@Override\\npublic void doOnUnregisteredError(String errorId)\\n{\\n    Log.e(TAG, \\\"Failed to unregister from pushes: \\\" + errorId);\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n**6.** Make sure your app is compatible to be used with **Test Devices** as outlined here:\n[http://docs.pushwoosh.com/docs/test-devices#android](http://docs.pushwoosh.com/docs/test-devices#android)\n\nThat’s it!","excerpt":"","slug":"android-sdk-fragments","type":"basic","title":"Android SDK"}
[**Download SDK**](https://github.com/Pushwoosh/pushwoosh-android-sdk) [**Sample Project**](https://github.com/Pushwoosh/pushwoosh-android-sdk/tree/master/Samples/Android-Simple) [block:callout] { "type": "info", "body": "This Android SDK integration guide uses Fragments." } [/block] [block:api-header] { "type": "basic", "title": "Gradle integration" } [/block] *Replace "+" with current version of Pushwoosh, Android Support and Google Play Services libraries* [block:code] { "codes": [ { "code": "compile 'com.pushwoosh:pushwoosh:+'\ncompile 'com.android.support:support-v4:+'\ncompile 'com.google.android.gms:play-services-gcm:+'\ncompile 'com.google.android.gms:play-services-location:+'", "language": "groovy" } ] } [/block] [block:api-header] { "type": "basic", "title": "Writing code" } [/block] **1**. In AndroidManifest.xml manifest add the following lines under application tag: [block:code] { "codes": [ { "code": "<meta-data android:name=\"PW_APPID\" android:value=\"XXXXX-XXXXX\" />\n<meta-data android:name=\"PW_PROJECT_ID\" android:value=\"A123456789012\" />", "language": "xml" } ] } [/block] Where: *PW_APPID* is your Pushwoosh Application Code *PW_PROJECT_ID* is the *Project Number* you received from Google ([Locate your Project Number](http://docs.pushwoosh.com/docs/android-faq#how-to-locate-my-google-project-number)), prefixed with A. **2.** Extend your Main activity from the **FragmentActivity** class and implement **PushEventListener** interface: [block:code] { "codes": [ { "code": "public class PushFragmentActivity extends FragmentActivity implements PushEventListener\n", "language": "java" } ] } [/block] **3.** In onCreate function call `PushFragment.init(this);` [block:code] { "codes": [ { "code": "@Override\nprotected void onCreate(Bundle savedInstanceState)\n{\n super.onCreate(savedInstanceState);\n \n //Init Pushwoosh fragment\n PushFragment.init(this);", "language": "java" } ] } [/block] **4.** In onNewIntent function call `PushFragment.onNewIntent(this, intent);` [block:code] { "codes": [ { "code": "@Override\npublic void onNewIntent(Intent intent)\n{\n super.onNewIntent(intent);\n \n //Check if we've got new intent with a push notification\n PushFragment.onNewIntent(this, intent);\n}", "language": "java" } ] } [/block] **5.** Implement callbacks as per **PushEventListener** interface: [block:code] { "codes": [ { "code": "@Override\npublic void doOnRegistered(String registrationId)\n{\n Log.i(TAG, \"Registered for pushes: \" + registrationId);\n}\n\n@Override\npublic void doOnRegisteredError(String errorId)\n{\n Log.e(TAG, \"Failed to register for pushes: \" + errorId);\n}\n\n@Override\npublic void doOnMessageReceive(String message)\n{\n Log.i(TAG, \"Notification opened: \" + message);\n}\n\n@Override\npublic void doOnUnregistered(final String message)\n{\n Log.i(TAG, \"Unregistered from pushes: \" + message);\n}\n\n@Override\npublic void doOnUnregisteredError(String errorId)\n{\n Log.e(TAG, \"Failed to unregister from pushes: \" + errorId);\n}", "language": "java" } ] } [/block] **6.** Make sure your app is compatible to be used with **Test Devices** as outlined here: [http://docs.pushwoosh.com/docs/test-devices#android](http://docs.pushwoosh.com/docs/test-devices#android) That’s it!