{"__v":156,"_id":"551ef4f04986f62b00a72076","category":{"__v":5,"_id":"551ef4ef4986f62b00a72035","pages":["551ef4f04986f62b00a72070","551ef4f04986f62b00a72071","551ef4f04986f62b00a72072","551ef4f04986f62b00a72073","551ef4f04986f62b00a72074","551ef4f04986f62b00a72075","551ef4f04986f62b00a72076","5522fc40b4a0de0d00de7f24","5524353371c0542100993567","5553aabaeac63f0d003e6c28","55f719077b40090d007a8004"],"project":"542b6018044e1e2200413772","version":"551ef4ef4986f62b00a7202e","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-10-20T19:30:50.610Z","from_sync":false,"order":2,"slug":"android","title":"Android"},"parentDoc":null,"project":"542b6018044e1e2200413772","user":"54455ea0a21e4d140055dc08","version":{"__v":10,"_id":"551ef4ef4986f62b00a7202e","forked_from":"542b6018044e1e2200413775","project":"542b6018044e1e2200413772","createdAt":"2015-04-03T20:15:43.149Z","releaseDate":"2015-04-03T20:15:43.149Z","categories":["551ef4ef4986f62b00a7202f","551ef4ef4986f62b00a72030","551ef4ef4986f62b00a72031","551ef4ef4986f62b00a72032","551ef4ef4986f62b00a72033","551ef4ef4986f62b00a72034","551ef4ef4986f62b00a72035","551ef4ef4986f62b00a72036","551ef4ef4986f62b00a72037","551ef4ef4986f62b00a72038","551ef4ef4986f62b00a72039","551ef4ef4986f62b00a7203a","551ef4ef4986f62b00a7203b","551ef4ef4986f62b00a7203c","551ef4ef4986f62b00a7203d","551ef4ef4986f62b00a7203e","55d7f1879510f00d007ec727","56b94a5a9fc0de1700b60ae9","56bd0e48ac1c5c1900b2dbe4","56d74afc3eb4dd0b0020196a","5723ab8a1f41110e003081ed","576b4dd327d6252b00085422","5792ca4369c5120e00efe023","5792ca55366dd20e004736d7","5792d30b23106419009c431b"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.0.0","version":"2.0"},"updates":["578028fd9a9ff80e0051be7c"],"createdAt":"2015-03-09T23:58:05.709Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":5,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Small Notification Icon\"\n}\n[/block]\nBy default, Our SDK automatically uses either a white bell icon or your App's launcher icon. Starting with Android 5, the OS forces the notification icon to be all white when your app targets Android API 21+. If you don't make a correct small icon, it will most likely be displayed as a bell or solid white icon in the status bar.\n\nTo quickly and easily generate small icons with the correct settings, we recommend using the [Android Asset Studio](http://romannurik.github.io/AndroidAssetStudio/icons-notification.html). Use `ic_stat_onesignal_default` as the name. Download and extract the `res` folder contents to your project and send out some test notifications to make sure it is working.\n[block:html]\n{\n  \"html\": \"<br>\"\n}\n[/block]\nIf you prefer to not use the Android Asset Studio please make your icon files in the following locations and sizes:\n###### Android 3.0 and higher.\nThese icons are expected to be entirely white.\n- `res/drawable-mdpi-v11/ic_stat_onesignal_default.png` 24x24 pixels\n- `res/drawable-hdpi-v11/ic_stat_onesignal_default.png` 36x36 pixels\n- `res/drawable-xhdpi-v11/ic_stat_onesignal_default.png` 48x48 pixels\n- `res/drawable-xxhdpi-v11/ic_stat_onesignal_default.png` 72x72 pixels\n\n###### Android 2.3 devices.\nThese icons are expected to be [grey(#828282 to #919191)](http://web.archive.org/web/20121025153046/http://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html#icon9).\n- `res/drawable-mdpi/ic_stat_onesignal_default.png` 24x24 pixels\n- `res/drawable-hdpi/ic_stat_onesignal_default.png` 36x36 pixels\n- `res/drawable-xhdpi/ic_stat_onesignal_default.png` 48x48 pixels\n- `res/drawable-xxhdpi/ic_stat_onesignal_default.png` 72x72 pixels\n[block:html]\n{\n  \"html\": \"<br>\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Large Notification Icon\"\n}\n[/block]\nThe large notification icon will show up to the left of the notification text on Android 3.0 and newer devices. If you do not set a large icon, the small icon will be used instead. If you want a default icon to be used, name it `ic_onesignal_large_icon_default` *(keeping the file extension)* and place it in the `res/drawable-xxhdpi-v11/` folder or in the root of your assets folder. You only need one icon file at 224x224 pixels as we will auto scale the image for you to prevent it from being cropped. You can also supply a URL where the icon will be displayed from.\n[block:html]\n{\n  \"html\": \"<br>\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Action Buttons\"\n}\n[/block]\nAndroid 4.1 and newer devices support actions buttons. You can specify up to 3 buttons that will display below your notification content. The button id is added to the additionalData variable in the notification opened callback. See the SDK API documentation for more details on looking for the id.\n\n###### Button Icons\nBy default icons will not display on the action buttons. If you're adding buttons to your notifications we highly recommend adding icons to them. You will need to make your icons 32x32dp (24x24dp optical square) in size, this means the following pixel sizes:\n```\nmdpi = 24x24 pixels in a 32x32 area\nhdpi = 36x36 pixels in a 48x48 area\nxhdpi = 48x48 pixels in a 64x64 area\nxxhdpi = 72x72 pixels in a 96x96 area\n```\n*See the image 'Big Picture' sample below to see what actions buttons look like on a notification.*\n<br>\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Big Picture\"\n}\n[/block]\nAndroid 4.1 and newer devices support a big picture that will show below your notification text when it is expanded. It can be located in your drawable folders, your assets folder in your app, or it can be loaded remotely from a server with a URL.\n\nThe image should be a 2:1 aspect ratio otherwise Android will crop your image. Android not have a size limit however see our recommended minimum, balanced, and maximum sizes below.\n* Minimum - 400x200\n* Balanced - 800x400\n* Maximum - 1440x720\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/bL7zcy7gScW42PDyFdhf_AndroidActionButtonsImageLinks-1.png\",\n        \"AndroidActionButtonsImageLinks-1.png\",\n        \"800\",\n        \"292\",\n        \"#438ed9\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n\n[block:html]\n{\n  \"html\": \"<br><br>\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Background Image\"\n}\n[/block]\nUsing our latest SDK you can add a background image to all your notifications by adding a image file named `onesignal_bgimage_default_image` to your `res/drawable-xxxhdpi` folder. The recommend size is 1582x256.\n\nUse `onesignal_bgimage_notif_title_color` and `onesignal_bgimage_notif_body_color` in your `values/colors.xml` to set text colors to match your image.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/ge1mfexQ0y8yCHSn5sag_CustomAndroid_Images_Blog.gif\",\n        \"CustomAndroid_Images_Blog.gif\",\n        600,\n        1067,\n        \"#323232\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nExample `color.xml` file. Title is set to red and the body is set to green below.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\"?>\\n<resources>\\n    <color name=\\\"onesignal_bgimage_notif_title_color\\\">#FFFF0000</color>\\n    <color name=\\\"onesignal_bgimage_notif_body_color\\\">#FF00FF00</color>\\n</resources>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\nNOTE: The app icon will be overridden by the background image. Include it as part of your image if you need it to show still.\n<br><br>\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Notification Stacking\"\n}\n[/block]\nSimply enter any value in the “Group Key” field under Options>Android on the New Message page on the dashboard. This is the `android_group` on the REST API. Notifications with the same group key will automatically stack on the device.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/GnEw4PmmSVWWfgX5Uc3W_stacked_notification.png\",\n        \"stacked_notification.png\",\n        \"900\",\n        \"460\",\n        \"#886865\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n- *Stacking works on all our latest SDKs and on Android devices all the way back to Android 2.3.*\n- If a group is set on a notification the changes made with `NotificationCompat.Builder` in the `NotificationExtenderService` will be ignored. This restriction fixed in a future SDK version.\n- *Also works on Amazon devices, set the group key listed under the amazon settings as well.*\n<br><br>\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"App Icon Badge counts\"\n}\n[/block]\nThe OneSignal SDK automatically sets the badge count on your app to the number of notifications that are currently in the notification shade. If you want to disable this you can add the following to your `AndroidManifest.xml`.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<application ...>\\n   <meta-data android:name=\\\"com.onesignal.BadgeCount\\\" android:value=\\\"DISABLE\\\" />\\n</application>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\nYou can remove the badge permissions with the following entries.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<uses-permission android:name=\\\"com.sec.android.provider.badge.permission.READ\\\" tools:node=\\\"remove\\\" />\\n<uses-permission android:name=\\\"com.sec.android.provider.badge.permission.WRITE\\\" tools:node=\\\"remove\\\" />\\n<uses-permission android:name=\\\"com.htc.launcher.permission.READ_SETTINGS\\\" tools:node=\\\"remove\\\" />\\n<uses-permission android:name=\\\"com.htc.launcher.permission.UPDATE_SHORTCUT\\\" tools:node=\\\"remove\\\" />\\n<uses-permission android:name=\\\"com.sonyericsson.home.permission.BROADCAST_BADGE\\\" tools:node=\\\"remove\\\" />\\n<uses-permission android:name=\\\"com.sonymobile.home.permission.PROVIDER_INSERT_BADGE\\\" tools:node=\\\"remove\\\" />\\n<uses-permission android:name=\\\"com.anddoes.launcher.permission.UPDATE_COUNT\\\" tools:node=\\\"remove\\\" />\\n<uses-permission android:name=\\\"com.majeur.launcher.permission.UPDATE_BADGE\\\" tools:node=\\\"remove\\\" />\\n<uses-permission android:name=\\\"com.huawei.android.launcher.permission.CHANGE_BADGE\\\" tools:node=\\\"remove\\\"/>\\n<uses-permission android:name=\\\"com.huawei.android.launcher.permission.READ_SETTINGS\\\" tools:node=\\\"remove\\\" />\\n<uses-permission android:name=\\\"com.huawei.android.launcher.permission.WRITE_SETTINGS\\\" tools:node=\\\"remove\\\" />\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n<br>\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Notification Sounds\"\n}\n[/block]\nBy default OneSignal automatically plays the default system notification sound. If you would like a custom one to always play instead, place a sound file in `res/raw/` and name it onesignal_default_sound *(keeping the file extension)*. You can use .wav, .mp3. or .ogg. If you would like to change the notification sound per notification you can add any other sound files in `res/raw` and include it's resource name (omit the file extension) in the sound field when sending the notification.\n\nIf you're having issues with the sound not playing, make sure that it is getting built into your APK by extracting it and make sure it is located in `res/raw/`.\n[block:html]\n{\n  \"html\": \"<br><br>\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Background Data and Notification Overriding\"\n}\n[/block]\nOneSignal supports sending additional data along with a notification as key value pairs. You can read this additional data when a notification is opened by adding a [NotificationOpenedHandler](android-sdk-api#NotificationOpenedHandler) instead.\n\nHowever if you want to one of the following continue with the instructions below.\n* Receive data in the background with or without displaying a notification.\n* Override specific notification settings depending on client side app logic such as custom accent color, vibration pattern, or other any other `NotificationCompat` options available.\n\n<br>\n**1.** Create a class that extents `NotificationExtenderService` and implement the `onNotificationProcessing` method.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import com.onesignal.OSNotificationPayload;\\nimport com.onesignal.NotificationExtenderService;\\n\\npublic class NotificationExtenderBareBonesExample extends NotificationExtenderService {\\n   :::at:::Override\\n   protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {\\n     \\t// Read properties from result.\\n     \\n      // Return true to stop the notification from displaying.\\n      return false;\\n   }\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n<br>\n**2.**  Add the following to your `AndroidManifest.xml`.\n*Replace 'YOUR_CLASS_NAME' with the class name you used above.*\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<service\\n   android:name=\\\".YOUR_CLASS_NAME\\\"\\n   android:exported=\\\"false\\\">\\n   <intent-filter>\\n      <action android:name=\\\"com.onesignal.NotificationExtender\\\" />\\n   </intent-filter>\\n</service>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n<br>\n**3.** To override or extend specific notification properties call `displayNotification` with `OverrideSettings`.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import android.support.v4.app.NotificationCompat;\\n\\nimport com.onesignal.OSNotificationPayload;\\nimport com.onesignal.NotificationExtenderService;\\n\\nimport java.math.BigInteger;\\n\\npublic class NotificationExtenderExample extends NotificationExtenderService {\\n   @Override\\n   protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {\\n      OverrideSettings overrideSettings = new OverrideSettings();\\n      overrideSettings.extender = new NotificationCompat.Extender() {\\n         @Override\\n         public NotificationCompat.Builder extend(NotificationCompat.Builder builder) {\\n            // Sets the background notification color to Green on Android 5.0+ devices.\\n            return builder.setColor(new BigInteger(\\\"FF00FF00\\\", 16).intValue());\\n         }\\n      };\\n\\n      OSNotificationDisplayedResult displayedResult = displayNotification(overrideSettings);\\n\\t\\t\\tLog.d(\\\"OneSignalExample\\\", \\\"Notification displayed with id: \\\" + displayedResult.androidNotificationId);\\n\\n      return true;\\n   }\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n**Additional Notes**\n`NotificationExtenderService` is an Android `IntentService` so please do all your work synchronously. A wake lock is obtained so the device will not sleep while you're processing the payload. \n\n<br><br>\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Resume last Activity when opening a Notification\"\n}\n[/block]\nAdd the following code to the top of `onCreate` in your launcher `Activity`.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"private static boolean activityStarted;\\n\\n@Override\\nprotected void onCreate(Bundle savedInstanceState) {\\n  super.onCreate(savedInstanceState);\\n\\n  if (   activityStarted\\n      && getIntent() != null\\n      && (getIntent().getFlags() & Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) {\\n  \\tfinish();\\n  \\treturn;\\n  }\\n  \\n  activityStarted = true;\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n**Additional information:** By default OneSignal calls `startActivity` with the following intent flags.\n```\nIntent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK\n```\n<br><br>\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Changing the open action of a notification\"\n}\n[/block]\nBy default OneSignal will open or resume your launcher Activity when a notification is tapped on. You can disable this behavior by adding the meta-data tag `com.onesignal.NotificationOpened.DEFAULT` set to `DISABLE` inside your application tag in your `AndroidManifest.xml`.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<application ...>\\n   <meta-data android:name=\\\"com.onesignal.NotificationOpened.DEFAULT\\\" android:value=\\\"DISABLE\\\" />\\n</application>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\nMake sure you are initializing `OneSignal` with [setNotificationOpenedHandler](android-sdk-api#setNotificationOpenedHandler) in the `onCreate` method in your `Application` class. You will need to call `startActivity` from this callback.\n<br><br>\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Example Project\"\n}\n[/block]\nWe have an example project with a custom sound, small icon, large icon, and a background data BroadcastReceiver [you can look at for reference.](https://github.com/one-signal/OneSignal-Android-SDK/tree/master/Examples)\n<br>\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Android SDK API Reference\"\n}\n[/block]\nSee our [Android SDK API Reference](https://documentation.onesignal.com/docs/android-sdk-api) for more customizations.","excerpt":"We highly recommend following at least our Small Notification Icon instructions below.","slug":"android-notification-customizations","type":"basic","title":"Customizing Notifications"}

Customizing Notifications

We highly recommend following at least our Small Notification Icon instructions below.

[block:api-header] { "type": "basic", "title": "Small Notification Icon" } [/block] By default, Our SDK automatically uses either a white bell icon or your App's launcher icon. Starting with Android 5, the OS forces the notification icon to be all white when your app targets Android API 21+. If you don't make a correct small icon, it will most likely be displayed as a bell or solid white icon in the status bar. To quickly and easily generate small icons with the correct settings, we recommend using the [Android Asset Studio](http://romannurik.github.io/AndroidAssetStudio/icons-notification.html). Use `ic_stat_onesignal_default` as the name. Download and extract the `res` folder contents to your project and send out some test notifications to make sure it is working. [block:html] { "html": "<br>" } [/block] If you prefer to not use the Android Asset Studio please make your icon files in the following locations and sizes: ###### Android 3.0 and higher. These icons are expected to be entirely white. - `res/drawable-mdpi-v11/ic_stat_onesignal_default.png` 24x24 pixels - `res/drawable-hdpi-v11/ic_stat_onesignal_default.png` 36x36 pixels - `res/drawable-xhdpi-v11/ic_stat_onesignal_default.png` 48x48 pixels - `res/drawable-xxhdpi-v11/ic_stat_onesignal_default.png` 72x72 pixels ###### Android 2.3 devices. These icons are expected to be [grey(#828282 to #919191)](http://web.archive.org/web/20121025153046/http://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html#icon9). - `res/drawable-mdpi/ic_stat_onesignal_default.png` 24x24 pixels - `res/drawable-hdpi/ic_stat_onesignal_default.png` 36x36 pixels - `res/drawable-xhdpi/ic_stat_onesignal_default.png` 48x48 pixels - `res/drawable-xxhdpi/ic_stat_onesignal_default.png` 72x72 pixels [block:html] { "html": "<br>" } [/block] [block:api-header] { "type": "basic", "title": "Large Notification Icon" } [/block] The large notification icon will show up to the left of the notification text on Android 3.0 and newer devices. If you do not set a large icon, the small icon will be used instead. If you want a default icon to be used, name it `ic_onesignal_large_icon_default` *(keeping the file extension)* and place it in the `res/drawable-xxhdpi-v11/` folder or in the root of your assets folder. You only need one icon file at 224x224 pixels as we will auto scale the image for you to prevent it from being cropped. You can also supply a URL where the icon will be displayed from. [block:html] { "html": "<br>" } [/block] [block:api-header] { "type": "basic", "title": "Action Buttons" } [/block] Android 4.1 and newer devices support actions buttons. You can specify up to 3 buttons that will display below your notification content. The button id is added to the additionalData variable in the notification opened callback. See the SDK API documentation for more details on looking for the id. ###### Button Icons By default icons will not display on the action buttons. If you're adding buttons to your notifications we highly recommend adding icons to them. You will need to make your icons 32x32dp (24x24dp optical square) in size, this means the following pixel sizes: ``` mdpi = 24x24 pixels in a 32x32 area hdpi = 36x36 pixels in a 48x48 area xhdpi = 48x48 pixels in a 64x64 area xxhdpi = 72x72 pixels in a 96x96 area ``` *See the image 'Big Picture' sample below to see what actions buttons look like on a notification.* <br> [block:api-header] { "type": "basic", "title": "Big Picture" } [/block] Android 4.1 and newer devices support a big picture that will show below your notification text when it is expanded. It can be located in your drawable folders, your assets folder in your app, or it can be loaded remotely from a server with a URL. The image should be a 2:1 aspect ratio otherwise Android will crop your image. Android not have a size limit however see our recommended minimum, balanced, and maximum sizes below. * Minimum - 400x200 * Balanced - 800x400 * Maximum - 1440x720 [block:image] { "images": [ { "image": [ "https://files.readme.io/bL7zcy7gScW42PDyFdhf_AndroidActionButtonsImageLinks-1.png", "AndroidActionButtonsImageLinks-1.png", "800", "292", "#438ed9", "" ] } ] } [/block] [block:html] { "html": "<br><br>" } [/block] [block:api-header] { "type": "basic", "title": "Background Image" } [/block] Using our latest SDK you can add a background image to all your notifications by adding a image file named `onesignal_bgimage_default_image` to your `res/drawable-xxxhdpi` folder. The recommend size is 1582x256. Use `onesignal_bgimage_notif_title_color` and `onesignal_bgimage_notif_body_color` in your `values/colors.xml` to set text colors to match your image. [block:image] { "images": [ { "image": [ "https://files.readme.io/ge1mfexQ0y8yCHSn5sag_CustomAndroid_Images_Blog.gif", "CustomAndroid_Images_Blog.gif", 600, 1067, "#323232", "" ] } ] } [/block] Example `color.xml` file. Title is set to red and the body is set to green below. [block:code] { "codes": [ { "code": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n <color name=\"onesignal_bgimage_notif_title_color\">#FFFF0000</color>\n <color name=\"onesignal_bgimage_notif_body_color\">#FF00FF00</color>\n</resources>", "language": "xml" } ] } [/block] NOTE: The app icon will be overridden by the background image. Include it as part of your image if you need it to show still. <br><br> [block:api-header] { "type": "basic", "title": "Notification Stacking" } [/block] Simply enter any value in the “Group Key” field under Options>Android on the New Message page on the dashboard. This is the `android_group` on the REST API. Notifications with the same group key will automatically stack on the device. [block:image] { "images": [ { "image": [ "https://files.readme.io/GnEw4PmmSVWWfgX5Uc3W_stacked_notification.png", "stacked_notification.png", "900", "460", "#886865", "" ] } ] } [/block] - *Stacking works on all our latest SDKs and on Android devices all the way back to Android 2.3.* - If a group is set on a notification the changes made with `NotificationCompat.Builder` in the `NotificationExtenderService` will be ignored. This restriction fixed in a future SDK version. - *Also works on Amazon devices, set the group key listed under the amazon settings as well.* <br><br> [block:api-header] { "type": "basic", "title": "App Icon Badge counts" } [/block] The OneSignal SDK automatically sets the badge count on your app to the number of notifications that are currently in the notification shade. If you want to disable this you can add the following to your `AndroidManifest.xml`. [block:code] { "codes": [ { "code": "<application ...>\n <meta-data android:name=\"com.onesignal.BadgeCount\" android:value=\"DISABLE\" />\n</application>", "language": "xml" } ] } [/block] You can remove the badge permissions with the following entries. [block:code] { "codes": [ { "code": "<uses-permission android:name=\"com.sec.android.provider.badge.permission.READ\" tools:node=\"remove\" />\n<uses-permission android:name=\"com.sec.android.provider.badge.permission.WRITE\" tools:node=\"remove\" />\n<uses-permission android:name=\"com.htc.launcher.permission.READ_SETTINGS\" tools:node=\"remove\" />\n<uses-permission android:name=\"com.htc.launcher.permission.UPDATE_SHORTCUT\" tools:node=\"remove\" />\n<uses-permission android:name=\"com.sonyericsson.home.permission.BROADCAST_BADGE\" tools:node=\"remove\" />\n<uses-permission android:name=\"com.sonymobile.home.permission.PROVIDER_INSERT_BADGE\" tools:node=\"remove\" />\n<uses-permission android:name=\"com.anddoes.launcher.permission.UPDATE_COUNT\" tools:node=\"remove\" />\n<uses-permission android:name=\"com.majeur.launcher.permission.UPDATE_BADGE\" tools:node=\"remove\" />\n<uses-permission android:name=\"com.huawei.android.launcher.permission.CHANGE_BADGE\" tools:node=\"remove\"/>\n<uses-permission android:name=\"com.huawei.android.launcher.permission.READ_SETTINGS\" tools:node=\"remove\" />\n<uses-permission android:name=\"com.huawei.android.launcher.permission.WRITE_SETTINGS\" tools:node=\"remove\" />", "language": "xml" } ] } [/block] <br> [block:api-header] { "type": "basic", "title": "Notification Sounds" } [/block] By default OneSignal automatically plays the default system notification sound. If you would like a custom one to always play instead, place a sound file in `res/raw/` and name it onesignal_default_sound *(keeping the file extension)*. You can use .wav, .mp3. or .ogg. If you would like to change the notification sound per notification you can add any other sound files in `res/raw` and include it's resource name (omit the file extension) in the sound field when sending the notification. If you're having issues with the sound not playing, make sure that it is getting built into your APK by extracting it and make sure it is located in `res/raw/`. [block:html] { "html": "<br><br>" } [/block] [block:api-header] { "type": "basic", "title": "Background Data and Notification Overriding" } [/block] OneSignal supports sending additional data along with a notification as key value pairs. You can read this additional data when a notification is opened by adding a [NotificationOpenedHandler](android-sdk-api#NotificationOpenedHandler) instead. However if you want to one of the following continue with the instructions below. * Receive data in the background with or without displaying a notification. * Override specific notification settings depending on client side app logic such as custom accent color, vibration pattern, or other any other `NotificationCompat` options available. <br> **1.** Create a class that extents `NotificationExtenderService` and implement the `onNotificationProcessing` method. [block:code] { "codes": [ { "code": "import com.onesignal.OSNotificationPayload;\nimport com.onesignal.NotificationExtenderService;\n\npublic class NotificationExtenderBareBonesExample extends NotificationExtenderService {\n @Override\n protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {\n \t// Read properties from result.\n \n // Return true to stop the notification from displaying.\n return false;\n }\n}", "language": "java" } ] } [/block] <br> **2.** Add the following to your `AndroidManifest.xml`. *Replace 'YOUR_CLASS_NAME' with the class name you used above.* [block:code] { "codes": [ { "code": "<service\n android:name=\".YOUR_CLASS_NAME\"\n android:exported=\"false\">\n <intent-filter>\n <action android:name=\"com.onesignal.NotificationExtender\" />\n </intent-filter>\n</service>", "language": "xml" } ] } [/block] <br> **3.** To override or extend specific notification properties call `displayNotification` with `OverrideSettings`. [block:code] { "codes": [ { "code": "import android.support.v4.app.NotificationCompat;\n\nimport com.onesignal.OSNotificationPayload;\nimport com.onesignal.NotificationExtenderService;\n\nimport java.math.BigInteger;\n\npublic class NotificationExtenderExample extends NotificationExtenderService {\n @Override\n protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {\n OverrideSettings overrideSettings = new OverrideSettings();\n overrideSettings.extender = new NotificationCompat.Extender() {\n @Override\n public NotificationCompat.Builder extend(NotificationCompat.Builder builder) {\n // Sets the background notification color to Green on Android 5.0+ devices.\n return builder.setColor(new BigInteger(\"FF00FF00\", 16).intValue());\n }\n };\n\n OSNotificationDisplayedResult displayedResult = displayNotification(overrideSettings);\n\t\t\tLog.d(\"OneSignalExample\", \"Notification displayed with id: \" + displayedResult.androidNotificationId);\n\n return true;\n }\n}", "language": "java" } ] } [/block] **Additional Notes** `NotificationExtenderService` is an Android `IntentService` so please do all your work synchronously. A wake lock is obtained so the device will not sleep while you're processing the payload. <br><br> [block:api-header] { "type": "basic", "title": "Resume last Activity when opening a Notification" } [/block] Add the following code to the top of `onCreate` in your launcher `Activity`. [block:code] { "codes": [ { "code": "private static boolean activityStarted;\n\n@Override\nprotected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n\n if ( activityStarted\n && getIntent() != null\n && (getIntent().getFlags() & Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) {\n \tfinish();\n \treturn;\n }\n \n activityStarted = true;\n}", "language": "java" } ] } [/block] **Additional information:** By default OneSignal calls `startActivity` with the following intent flags. ``` Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK ``` <br><br> [block:api-header] { "type": "basic", "title": "Changing the open action of a notification" } [/block] By default OneSignal will open or resume your launcher Activity when a notification is tapped on. You can disable this behavior by adding the meta-data tag `com.onesignal.NotificationOpened.DEFAULT` set to `DISABLE` inside your application tag in your `AndroidManifest.xml`. [block:code] { "codes": [ { "code": "<application ...>\n <meta-data android:name=\"com.onesignal.NotificationOpened.DEFAULT\" android:value=\"DISABLE\" />\n</application>", "language": "xml" } ] } [/block] Make sure you are initializing `OneSignal` with [setNotificationOpenedHandler](android-sdk-api#setNotificationOpenedHandler) in the `onCreate` method in your `Application` class. You will need to call `startActivity` from this callback. <br><br> [block:api-header] { "type": "basic", "title": "Example Project" } [/block] We have an example project with a custom sound, small icon, large icon, and a background data BroadcastReceiver [you can look at for reference.](https://github.com/one-signal/OneSignal-Android-SDK/tree/master/Examples) <br> [block:api-header] { "type": "basic", "title": "Android SDK API Reference" } [/block] See our [Android SDK API Reference](https://documentation.onesignal.com/docs/android-sdk-api) for more customizations.