Skip to content

Enabling notifications

Patryk Michalik edited this page Sep 15, 2022 · 5 revisions

This feature is completely optional. If you don't want to implement this, you can just ignore the content of this page.

Note
OneSignal collects some data, and this should be reflected in the “Data safety” section of your app’s Play Store listing. In the Play Console, declare that your app collects data of the “Device or other IDs” type. See the OneSignal documentation and the Play Console documentation for more information.

Steps:

  1. Create an account on OneSignal.

  2. Generate the required API keys following this tutorial.

  3. Open this file: app/build.gradle

  4. Just so you know, the comment marks are these: /* and */ and //

  5. Do NOT sync gradle until you reach step 8. This is important.

  6. Check these lines and remove the comments in them:

    Careful! When you remove lines, the lines numbers will change, but you can easily find them by the comment marks.

  7. Open the file buildSrc/src/main/java/OneSignal.kt

    • appId at line #4. Put the key OneSignal gives to you.
    • googleProjectNumber at line #5. Put the key Firebase gives to you.
  8. You can now sync gradle

  9. Go to this file: app/src/main/kotlin/your/package/name/NotificationServiceExtension.kt and remove the comment marks at lines 3 and 29.

  10. Go to this file: app/src/main/kotlin/your/package/name/MyApplication.kt and remove the comment marks at lines 6, 7, 8, 14 and 26.

  11. Clean and rebuild your project.

  12. Run your app and test notifications from OneSignal's console.

  13. If you want to change your notifications icon, just create a Vector Drawable XML icon and put it inside this folder: app/src/main/res/drawable with the name ic_notification.xml.

Clone this wiki locally