{"_id":"570164bc9433720e00080db1","category":{"_id":"56d369331660770b00081159","__v":5,"project":"56cecbdb44c5700b0095c03a","pages":["56d403d87e7f160b00cd10a8","56e51bf22d90970e00af1b18","56e527ad75eb791700a9c4c4","56e538732d90970e00af1b28","56e6941a0d2f0f0e009326b0"],"version":"56cecbdc44c5700b0095c03d","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-28T21:40:03.218Z","from_sync":false,"order":1,"slug":"android","title":"Android"},"githubsync":"","project":"56cecbdb44c5700b0095c03a","__v":9,"user":"56cecbb2e50c9c1b008303eb","parentDoc":null,"version":{"_id":"56cecbdc44c5700b0095c03d","project":"56cecbdb44c5700b0095c03a","__v":10,"createdAt":"2016-02-25T09:39:40.121Z","releaseDate":"2016-02-25T09:39:40.121Z","categories":["56cecbdc44c5700b0095c03e","56d1d2c05ad7ad0b00b7e809","56d1d2fa5ad7ad0b00b7e80a","56d369331660770b00081159","56d3693d1660770b0008115a","56e5361e7990160e002e3fbc","56e5362775eb791700a9c4d2","57a9030947f2f419009188d4","57b4705ee9e4c60e00f6f4c3","5828f5b04774ab0f005179a2"],"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":"2016-04-03T18:45:16.152Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"In order to get to know to your users better, and to fit them with the best content and features, our platform can offer, please go through the following steps.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"1. Enabling and disabling push notificaionts\"\n}\n[/block]\nIn many case you would want your users to have a choice wether they wish to receive pushes or not.\nTo enable push notifications:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.enablePush(getApplicationContext(),true);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nTo disable push notifications:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.enablePush(getApplicationContext(),false);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nTo check the user's current status:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"boolean pushEnabled = PushApps.isPushEnabled(getApplicationContext());\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"2. Articles and content read by the user\"\n}\n[/block]\nUpdate PushApps SDK with any content read by the user. This content must have a URL connected to it. Place the following line, right after the user consume the content:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"String urlReadByTheUser = \\\"http://....\\\";\\nPushApps.trackUrlView(getApplicationContext(), urlReadByTheUser);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"3. Handling GCM registration\"\n}\n[/block]\nYou can extract the device push token, once registered with the GCM:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.setGcmListener(this, new PAGcmListener() {\\n\\n\\t\\t\\t:::at:::Override\\n\\t\\t\\tpublic void onGcmRegistrationFinished(String token, String errorMeassge) {\\n\\t\\t\\t\\tif (token != null) {\\n\\t\\t\\t\\t\\tLog.d(TAG, \\\"Your GCM token is: \\\" + token);\\n\\t\\t\\t\\t} else {\\n\\t\\t\\t\\t\\tLog.d(TAG, \\\"Could not register to the GCM service: \\\" + errorMeassge);\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"4. Setting notification icon background color\"\n}\n[/block]\nTo change the default notification icon background color, you can call the following code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.setNotificationIconBackgroundColor(context, R.color.my_color);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"5. Change the notification small view background color\"\n}\n[/block]\nIn order to set your own custom color, as the background of the notification small view, please use the following code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.setNotificationSmallViewBackgroundColor(context, R.color.my_color);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"6. Use the application icon as the default image\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.setIconAsDefaultImageForSmallView(context, true);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"7. Getting an article URL from a poll notification\"\n}\n[/block]\nSending a poll notification, is a powerful toll to interact with your users. After the user clicked on an answer, the app will automatically open, and he will be able to see the global result of this poll.\nSometimes, you would like to connect the poll to an article. In order to show the user the article, after answering the poll, add the following code to your main activity:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Bundle bundle = getIntent().getExtras();\\nif (bundle != null) {\\n\\tif (bundle.containsKey(PAPopup.PAPollArticleUrl)) {\\n  \\tString pollArticleUrl = bundle.getString(PAPopup.PAPollArticleUrl);\\n  }\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"8. Change Drag To Expand image\"\n}\n[/block]\nThe \"Drag To Expand\" image helps your users to identify that there is more content to notification, while in collapsed mode. To show your own custom image, please use the following code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.setDragToExpandDrawable(context, R.drawable.your_custom_drag_to_expand);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"9. Customizing notifications\"\n}\n[/block]\nYou can control wether a device will display notifications with sound and vibration.\nVibration is controlled on a device level settings from the SDK.\nSound can be sent in the notification payload from our dashboard and API, and will be override by the device level settings from the SDK, if there were any.\nUse ```default``` or leave the sound field empty for the default device notification sound.\nTo disable sound:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.enableSound(getActivity().getApplicationContext(),false);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nTo disable vibration:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.enableVibrate(getActivity().getApplicationContext(),false);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nTo get the current settings:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"boolean soundEnabled = PushApps.isSoundEnabled(getApplicationContext());\\nboolean vibrationEnabled = PushApps.isVibrateEnabled(getApplicationContext());\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"If you want to have a silent notification, pass \\\"silent\\\" as the notification sound in the notification payload from the dashboard and API. The notification will be silent even if the user didn't disable sound for notifications.\",\n  \"title\": \"Silent Notifications\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"10. Launching with a different activity\"\n}\n[/block]\nBy default, external push providers and PushApps as well will launch the default launching `Activity` ( with the `intent-filter` of `android.intent.category.LAUNCHER` . If you want to change that behavior for a specific notification you can do it with one of the following options:\n1. **If you are using PushApps as your push provider:**\nadd the following `meta-data` tag to the 'application' tag inside the `AndroidManifest.xml` file:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<meta-data\\n           android:name=\\\"PushApps_DefaultLaunchIntentClass\\\"\\n           android:value=\\\"mobi.pushapps.demo.OtherActivity\\\">\\n</meta-data>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n2. **If you are using an external push provider:**\nby using the notification builder and setting `launchIntentClassName` to the fully qualified package name of the `Activity`:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PANotification notification = new PANotification.Builder()\\n                        .campaignId(campaignId)\\n                        .text(notificationMessage)\\n                        .sound(notificationSound)\\n                        .title(notificationTitle)\\n                        .url(notificationUrl)\\n                        .imageUrl(notificationImage)\\n                        .launchIntentClassName(\\\"mobi.pushapps.demo.SampleActivity\\\")\\n                        .build();\\n                PushApps.buildNotification(getApplicationContext(), extras, notification,null);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nIn any case, option 2 will override option 1.\n\nThis feature will work only with providers who enable this behavior for specific notification. For example - it won't work with PushWoosh, but will work with OneSignal. Please contact us for more information.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"11. Set the push registration id manually\"\n}\n[/block]\nIn case you want to use PushApps just for push enrichment, without us handling the registration with GCM/FCM for you, you can just manually set the registration id : \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.setRegistrationId(getApplicationContext(),\\\"my-registration-id\\\");\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"12. Setting your own default notification sound\"\n}\n[/block]\nPlace your sound in the `raw` folder under the `res` folder and call the following method with the file name:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PushApps.setDefaultSoundName(getApplicationContext(), \\\"beep\\\");\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"android-advanced-features","type":"basic","title":"Advanced Features"}
In order to get to know to your users better, and to fit them with the best content and features, our platform can offer, please go through the following steps. [block:api-header] { "type": "basic", "title": "1. Enabling and disabling push notificaionts" } [/block] In many case you would want your users to have a choice wether they wish to receive pushes or not. To enable push notifications: [block:code] { "codes": [ { "code": "PushApps.enablePush(getApplicationContext(),true);", "language": "java" } ] } [/block] To disable push notifications: [block:code] { "codes": [ { "code": "PushApps.enablePush(getApplicationContext(),false);", "language": "java" } ] } [/block] To check the user's current status: [block:code] { "codes": [ { "code": "boolean pushEnabled = PushApps.isPushEnabled(getApplicationContext());", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "2. Articles and content read by the user" } [/block] Update PushApps SDK with any content read by the user. This content must have a URL connected to it. Place the following line, right after the user consume the content: [block:code] { "codes": [ { "code": "String urlReadByTheUser = \"http://....\";\nPushApps.trackUrlView(getApplicationContext(), urlReadByTheUser);", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "3. Handling GCM registration" } [/block] You can extract the device push token, once registered with the GCM: [block:code] { "codes": [ { "code": "PushApps.setGcmListener(this, new PAGcmListener() {\n\n\t\t\t@Override\n\t\t\tpublic void onGcmRegistrationFinished(String token, String errorMeassge) {\n\t\t\t\tif (token != null) {\n\t\t\t\t\tLog.d(TAG, \"Your GCM token is: \" + token);\n\t\t\t\t} else {\n\t\t\t\t\tLog.d(TAG, \"Could not register to the GCM service: \" + errorMeassge);\n\t\t\t\t}\n\t\t\t}\n\t\t});", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "4. Setting notification icon background color" } [/block] To change the default notification icon background color, you can call the following code: [block:code] { "codes": [ { "code": "PushApps.setNotificationIconBackgroundColor(context, R.color.my_color);", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "5. Change the notification small view background color" } [/block] In order to set your own custom color, as the background of the notification small view, please use the following code: [block:code] { "codes": [ { "code": "PushApps.setNotificationSmallViewBackgroundColor(context, R.color.my_color);", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "6. Use the application icon as the default image" } [/block] [block:code] { "codes": [ { "code": "PushApps.setIconAsDefaultImageForSmallView(context, true);", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "7. Getting an article URL from a poll notification" } [/block] Sending a poll notification, is a powerful toll to interact with your users. After the user clicked on an answer, the app will automatically open, and he will be able to see the global result of this poll. Sometimes, you would like to connect the poll to an article. In order to show the user the article, after answering the poll, add the following code to your main activity: [block:code] { "codes": [ { "code": "Bundle bundle = getIntent().getExtras();\nif (bundle != null) {\n\tif (bundle.containsKey(PAPopup.PAPollArticleUrl)) {\n \tString pollArticleUrl = bundle.getString(PAPopup.PAPollArticleUrl);\n }\n}", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "8. Change Drag To Expand image" } [/block] The "Drag To Expand" image helps your users to identify that there is more content to notification, while in collapsed mode. To show your own custom image, please use the following code: [block:code] { "codes": [ { "code": "PushApps.setDragToExpandDrawable(context, R.drawable.your_custom_drag_to_expand);", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "9. Customizing notifications" } [/block] You can control wether a device will display notifications with sound and vibration. Vibration is controlled on a device level settings from the SDK. Sound can be sent in the notification payload from our dashboard and API, and will be override by the device level settings from the SDK, if there were any. Use ```default``` or leave the sound field empty for the default device notification sound. To disable sound: [block:code] { "codes": [ { "code": "PushApps.enableSound(getActivity().getApplicationContext(),false);", "language": "java" } ] } [/block] To disable vibration: [block:code] { "codes": [ { "code": "PushApps.enableVibrate(getActivity().getApplicationContext(),false);", "language": "java" } ] } [/block] To get the current settings: [block:code] { "codes": [ { "code": "boolean soundEnabled = PushApps.isSoundEnabled(getApplicationContext());\nboolean vibrationEnabled = PushApps.isVibrateEnabled(getApplicationContext());", "language": "java" } ] } [/block] [block:callout] { "type": "info", "body": "If you want to have a silent notification, pass \"silent\" as the notification sound in the notification payload from the dashboard and API. The notification will be silent even if the user didn't disable sound for notifications.", "title": "Silent Notifications" } [/block] [block:api-header] { "type": "basic", "title": "10. Launching with a different activity" } [/block] By default, external push providers and PushApps as well will launch the default launching `Activity` ( with the `intent-filter` of `android.intent.category.LAUNCHER` . If you want to change that behavior for a specific notification you can do it with one of the following options: 1. **If you are using PushApps as your push provider:** add the following `meta-data` tag to the 'application' tag inside the `AndroidManifest.xml` file: [block:code] { "codes": [ { "code": "<meta-data\n android:name=\"PushApps_DefaultLaunchIntentClass\"\n android:value=\"mobi.pushapps.demo.OtherActivity\">\n</meta-data>", "language": "xml" } ] } [/block] 2. **If you are using an external push provider:** by using the notification builder and setting `launchIntentClassName` to the fully qualified package name of the `Activity`: [block:code] { "codes": [ { "code": "PANotification notification = new PANotification.Builder()\n .campaignId(campaignId)\n .text(notificationMessage)\n .sound(notificationSound)\n .title(notificationTitle)\n .url(notificationUrl)\n .imageUrl(notificationImage)\n .launchIntentClassName(\"mobi.pushapps.demo.SampleActivity\")\n .build();\n PushApps.buildNotification(getApplicationContext(), extras, notification,null);", "language": "java" } ] } [/block] In any case, option 2 will override option 1. This feature will work only with providers who enable this behavior for specific notification. For example - it won't work with PushWoosh, but will work with OneSignal. Please contact us for more information. [block:api-header] { "type": "basic", "title": "11. Set the push registration id manually" } [/block] In case you want to use PushApps just for push enrichment, without us handling the registration with GCM/FCM for you, you can just manually set the registration id : [block:code] { "codes": [ { "code": "PushApps.setRegistrationId(getApplicationContext(),\"my-registration-id\");", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "12. Setting your own default notification sound" } [/block] Place your sound in the `raw` folder under the `res` folder and call the following method with the file name: [block:code] { "codes": [ { "code": "PushApps.setDefaultSoundName(getApplicationContext(), \"beep\");", "language": "java" } ] } [/block]