{"_id":"594c9e9f69962b00152fe0be","project":"5540ce1b31827a0d007ab1cc","version":{"_id":"5540ce1c31827a0d007ab1cf","project":"5540ce1b31827a0d007ab1cc","__v":31,"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"},"category":{"_id":"5540e5f131827a0d007ab212","__v":15,"project":"5540ce1b31827a0d007ab1cc","pages":["5540e66b31827a0d007ab217","5540e67731827a0d007ab219","55ac917b5863b817008ae3b4","55acaa4c6b4ff90d00784a92","55acb96418eefd0d0071d553","55acc8aa18eefd0d0071d596","55accd2818eefd0d0071d5a8","55acd06518eefd0d0071d5b6","55acddd7fb7b3c19003739cc","55ace14bfb7b3c19003739d3","55ace3a9fb7b3c19003739d7","55acea24f93f0c0d005b880f","55acf15bf93f0c0d005b8821","55acf3cd18eefd0d0071d5fb","55d1f1c0486de50d00326f17"],"version":"5540ce1c31827a0d007ab1cf","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-04-29T14:08:49.271Z","from_sync":false,"order":4,"slug":"android","title":"Android"},"user":"55b8b82fdec1c9210013cfa1","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-06-23T04:52:47.817Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":9,"body":"Most of Pushwoosh classes and methods became deprecated since 5.0 release and some of them became extinct. **PushManager**, **BasePushMessageReceiver**, **BaseRegistrationReceiver**, **SendPushTagsCallback**, **PushFragment** and **PushEventListener** classes are still available as part of `com.pushwoosh:pushwoosh-deprecated` library but it is recommended to migrate to new API as soon as possible.\n[block:api-header]\n{\n  \"title\": \"PushManager\"\n}\n[/block]\n**PushManager** consisted of various methods for different features. These methods are now split between different classes and libraries:\n`com.pushwoosh:pushwoosh`: **Pushwoosh**, **PushwooshNotificationSettings**, **PushwooshInApp**.\n`com.pushwoosh:pushwoosh-badge`: **PushwooshBadge**.\n`com.pushwoosh:pushwoosh-location`: **PushwooshLocation**.\n`com.pushwoosh:pushwoosh-beacon`: **PushwooshBeacon**.\n[block:api-header]\n{\n  \"title\": \"BaseRegistrationReceiver\"\n}\n[/block]\n**BaseRegistrationReceiver** was used to handle push registration and unregistration events. This receiver is now replaced by simple callback mechanism:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Pushwoosh.getInstance().registerForPushNotifications(result -> {\\n    if (result.isSuccess()) {\\n        String token = result.getData();\\n        // handle successful registration\\n    }\\n    else {\\n        PushwooshException exception = result.getException();\\n        // handle registration error\\n    }\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"BasePushMessageReceiver\"\n}\n[/block]\n**BasePushMessageReceiver** was used to imitate iOS notification behaviour when receiving push notification in foreground. It was achieved by cancelling incoming notification and invoking **onMessageReceive** callback. It was clunky and required manual registration when application becomes active and deregistration when application goes background.\nThis receiver was replaced by **NotificationServiceExtension**:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<meta-data\\n    android:name=\\\"com.pushwoosh.notification_service_extension\\\"\\n    android:value=\\\"com.your.package.name.YourNotificationServiceExtension\\\"/>\",\n      \"language\": \"xml\",\n      \"name\": \"AndroidManifest.xml\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public class YourNotificationServiceExtension extends NotificationServiceExtension {\\n    :::at:::Override\\n    public boolean onMessageReceived(final PushMessage message) {\\n        if (isAppOnForeground()) {\\n            Handler mainHandler = new Handler(getApplicationContext().getMainLooper());\\n            mainHandler.post(() -> {\\n                handlePush(message);\\n            });\\n\\n            // this indicates that notification should not be displayed\\n            return true;\\n        }\\n\\n        return false;\\n    }\\n\\n    @Override\\n    protected void startActivityForPushMessage(PushMessage message) {\\n        super.startActivityForPushMessage(message);\\n        handlePush(message);\\n    }\\n\\n    @MainThread\\n    private void handlePush(PushMessage message) {\\n        // TODO: handle push message\\n    }\\n}\",\n      \"language\": \"java\",\n      \"name\": \"YourNotificationServiceExtension.java\"\n    }\n  ]\n}\n[/block]\nThis extension is also used to handle notification arrival and accept events thus replacing all clunky code that was used in manual Activity integration. \n[block:api-header]\n{\n  \"title\": \"PushFragment\"\n}\n[/block]\n**PushFragment** was a lightweight alternative for the complex integration involving Activity lifecycle. But on the other hand it required **FragmentActivity** inheritance and implicitly used more complex Fragment lifecycle.\n**PushFragment** and **PushEventListener** are now replaced by **Pushwoosh#registerForPushNotifications(Callback)** and **NotificationServiceExtension**.\n[block:api-header]\n{\n  \"title\": \"Custom Push Broadcast Receiver (PW_NOTIFICATION_RECEIVER)\"\n}\n[/block]\n**PW_NOTIFICATION_RECEIVER** was used to customise behaviour when user clicks on notification. This allowed to handle notifications outside of Activity context and to open different Activities depending on notification content. This integration used internal Pushwoosh SDK API which no longer exists.\nThis receiver is now completely replaced by **NotificationServiceExtension**:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public class YourNotificationServiceExtension extends NotificationServiceExtension {\\n    @Override\\n    protected void startActivityForPushMessage(PushMessage message) {\\n    \\t// super.startActivityForPushMessage() starts default launcher activity \\n    \\t// or activity marked with ${applicationId}.MESSAGE action.\\n    \\t// Simply do not call it to override this behaviour.\\n        // super.startActivityForPushMessage(message);\\n\\n        // start your activity instead:\\n        Intent launchIntent  = new Intent(getApplicationContext(), YourActivity.class);             \\n        launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);\\n \\n        // (Optional) pass notification data to Activity\\n        launchIntent.putExtra(Pushwoosh.PUSH_RECEIVE_EVENT, message.toJson().toString());\\n \\n        context.startActivity(launchIntent);\\n    }\\n}\",\n      \"language\": \"java\",\n      \"name\": \"YourNotificationServiceExtension.java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Notification Factory\"\n}\n[/block]\nThere also were some breaking changes involving notification factory:\n\n**1.** ** AbsNotificationFactory** was replaced by **NotificationFactory**\n**2.** **AbsNotificationFactory#onPushReceived(PushData)** and **AbsNotificationFactory#onPushHandle(Activity)** methods replaced by **NotificationServiceExtension** class (**onMessageReceived**, **startActivityForPushMessage**).\n**3.** **DefaultNotificationFactory** was replaced by **PushwooshNotificationFactory**.\n**4.** **PushData** was replaced by **PushMessage**.\n[block:api-header]\n{\n  \"title\": \"In-App Messages\"\n}\n[/block]\n**1.** **InAppFacade** was replaced by **PushwooshInApp**.\n**2.**  `pushwoosh` object was inroduced for JavaScript native interface with following API:\n**getHwid(): string** - returns pushwoosh hwid for current device.\n**getVersion(): string** - returns current pushwoosh SDK version.\n**postEvent(event: string, attributes?: object, successCallback?: function, errorCallback?: function)** - sends postEvent request.\n**sendTags(tags: object)** - send tags associated with current device.\n**getTags(successCallback: function, errorCallback?: function)** - returns tags associated with current device.\n**closeInApp()** - closes In-App html page.","excerpt":"","slug":"pushwoosh-android-sdk-50-migration-guide","type":"basic","title":"Migration to Android SDK 5.0"}

Migration to Android SDK 5.0


Most of Pushwoosh classes and methods became deprecated since 5.0 release and some of them became extinct. **PushManager**, **BasePushMessageReceiver**, **BaseRegistrationReceiver**, **SendPushTagsCallback**, **PushFragment** and **PushEventListener** classes are still available as part of `com.pushwoosh:pushwoosh-deprecated` library but it is recommended to migrate to new API as soon as possible. [block:api-header] { "title": "PushManager" } [/block] **PushManager** consisted of various methods for different features. These methods are now split between different classes and libraries: `com.pushwoosh:pushwoosh`: **Pushwoosh**, **PushwooshNotificationSettings**, **PushwooshInApp**. `com.pushwoosh:pushwoosh-badge`: **PushwooshBadge**. `com.pushwoosh:pushwoosh-location`: **PushwooshLocation**. `com.pushwoosh:pushwoosh-beacon`: **PushwooshBeacon**. [block:api-header] { "title": "BaseRegistrationReceiver" } [/block] **BaseRegistrationReceiver** was used to handle push registration and unregistration events. This receiver is now replaced by simple callback mechanism: [block:code] { "codes": [ { "code": "Pushwoosh.getInstance().registerForPushNotifications(result -> {\n if (result.isSuccess()) {\n String token = result.getData();\n // handle successful registration\n }\n else {\n PushwooshException exception = result.getException();\n // handle registration error\n }\n});", "language": "java" } ] } [/block] [block:api-header] { "title": "BasePushMessageReceiver" } [/block] **BasePushMessageReceiver** was used to imitate iOS notification behaviour when receiving push notification in foreground. It was achieved by cancelling incoming notification and invoking **onMessageReceive** callback. It was clunky and required manual registration when application becomes active and deregistration when application goes background. This receiver was replaced by **NotificationServiceExtension**: [block:code] { "codes": [ { "code": "<meta-data\n android:name=\"com.pushwoosh.notification_service_extension\"\n android:value=\"com.your.package.name.YourNotificationServiceExtension\"/>", "language": "xml", "name": "AndroidManifest.xml" } ] } [/block] [block:code] { "codes": [ { "code": "public class YourNotificationServiceExtension extends NotificationServiceExtension {\n @Override\n public boolean onMessageReceived(final PushMessage message) {\n if (isAppOnForeground()) {\n Handler mainHandler = new Handler(getApplicationContext().getMainLooper());\n mainHandler.post(() -> {\n handlePush(message);\n });\n\n // this indicates that notification should not be displayed\n return true;\n }\n\n return false;\n }\n\n @Override\n protected void startActivityForPushMessage(PushMessage message) {\n super.startActivityForPushMessage(message);\n handlePush(message);\n }\n\n @MainThread\n private void handlePush(PushMessage message) {\n // TODO: handle push message\n }\n}", "language": "java", "name": "YourNotificationServiceExtension.java" } ] } [/block] This extension is also used to handle notification arrival and accept events thus replacing all clunky code that was used in manual Activity integration. [block:api-header] { "title": "PushFragment" } [/block] **PushFragment** was a lightweight alternative for the complex integration involving Activity lifecycle. But on the other hand it required **FragmentActivity** inheritance and implicitly used more complex Fragment lifecycle. **PushFragment** and **PushEventListener** are now replaced by **Pushwoosh#registerForPushNotifications(Callback)** and **NotificationServiceExtension**. [block:api-header] { "title": "Custom Push Broadcast Receiver (PW_NOTIFICATION_RECEIVER)" } [/block] **PW_NOTIFICATION_RECEIVER** was used to customise behaviour when user clicks on notification. This allowed to handle notifications outside of Activity context and to open different Activities depending on notification content. This integration used internal Pushwoosh SDK API which no longer exists. This receiver is now completely replaced by **NotificationServiceExtension**: [block:code] { "codes": [ { "code": "public class YourNotificationServiceExtension extends NotificationServiceExtension {\n @Override\n protected void startActivityForPushMessage(PushMessage message) {\n \t// super.startActivityForPushMessage() starts default launcher activity \n \t// or activity marked with ${applicationId}.MESSAGE action.\n \t// Simply do not call it to override this behaviour.\n // super.startActivityForPushMessage(message);\n\n // start your activity instead:\n Intent launchIntent = new Intent(getApplicationContext(), YourActivity.class); \n launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);\n \n // (Optional) pass notification data to Activity\n launchIntent.putExtra(Pushwoosh.PUSH_RECEIVE_EVENT, message.toJson().toString());\n \n context.startActivity(launchIntent);\n }\n}", "language": "java", "name": "YourNotificationServiceExtension.java" } ] } [/block] [block:api-header] { "title": "Notification Factory" } [/block] There also were some breaking changes involving notification factory: **1.** ** AbsNotificationFactory** was replaced by **NotificationFactory** **2.** **AbsNotificationFactory#onPushReceived(PushData)** and **AbsNotificationFactory#onPushHandle(Activity)** methods replaced by **NotificationServiceExtension** class (**onMessageReceived**, **startActivityForPushMessage**). **3.** **DefaultNotificationFactory** was replaced by **PushwooshNotificationFactory**. **4.** **PushData** was replaced by **PushMessage**. [block:api-header] { "title": "In-App Messages" } [/block] **1.** **InAppFacade** was replaced by **PushwooshInApp**. **2.** `pushwoosh` object was inroduced for JavaScript native interface with following API: **getHwid(): string** - returns pushwoosh hwid for current device. **getVersion(): string** - returns current pushwoosh SDK version. **postEvent(event: string, attributes?: object, successCallback?: function, errorCallback?: function)** - sends postEvent request. **sendTags(tags: object)** - send tags associated with current device. **getTags(successCallback: function, errorCallback?: function)** - returns tags associated with current device. **closeInApp()** - closes In-App html page.