Skip to content
Dashbud

Enable Notifications

You can send notifications to your users, for example when you add new wallpapers. Kuper uses OneSignal for this, together with Firebase.

This is completely optional. If you don’t need notifications, skip this page.

Important

OneSignal collects some data, and you have to declare it in the “Data safety” section of your Play Store listing: your app collects “Device or other IDs”. See the OneSignal documentation and the Play Console documentation.

Make sure your package name is set up: see Set Package Name. Notifications rely on it.

Follow OneSignal’s guide to create a Firebase project and a OneSignal app. Write down two values:

  • Your OneSignal App ID
  • Your Firebase Sender ID (also called project number)

Open buildSrc/src/main/java/OneSignal.kt and replace both values with yours:

object OneSignal {
const val appId = "your-onesignal-app-id"
const val googleProjectNumber = "your-firebase-sender-id"
}

The notifications code is already in your project, but it’s turned off with comment marks. You’ll remove them in four files.

Comment marks look like this:

  • // at the start of a line turns off that one line.
  • /* and */ turn off everything between them.

Each place you need to change is marked with a TODO: Remove comment marks to enable comment. To find them all, open Edit → Find → Find in Files and search for Remove comment marks to enable.

Remove the // before implementation:

dependencies {
implementation(Libs.kuper) {
transitive = true
}
// TODO: Remove comment marks to enable
implementation Libs.oneSignal
}

Remove the // from the three import lines, and the /* and */ around the OneSignal code inside onCreate. It should end up like this:

import com.onesignal.OneSignal
import com.onesignal.OSNotificationReceivedEvent
import dev.jahir.frames.extensions.context.preferences
class MyApplication : FramesApplication(BuildConfig.ONESIGNAL_APP_ID) {
override fun onCreate() {
super.onCreate()
OneSignal.initWithContext(this);
OneSignal.setAppId(BuildConfig.ONESIGNAL_APP_ID);
// ...the rest of the OneSignal code
}
}

NotificationServiceExtension.kt (in your package folder)

Section titled “NotificationServiceExtension.kt (in your package folder)”

Remove the /* near the top and the */ at the end of the file.

Then check the line that imports R. It must use your package name:

import com.yourname.yourapp.R

Near the end of the file, remove the <!-- line and the --> line around the OneSignal meta-data:

<!-- OneSignal Notifications Service -->
<meta-data android:name="com.onesignal.NotificationServiceExtension"
android:value="${applicationId}.NotificationServiceExtension" />
  1. Click File → Sync Project with Gradle Files.
  2. Run the app on your phone or emulator and allow notifications when it asks.
  3. In your OneSignal dashboard, send a test notification. It should show up on your device. 🔔

The small icon in the status bar comes from app/src/main/res/drawable/ic_notification.xml. To use your own, replace that file with a vector drawable with the same name. Android shows it as a white silhouette, so use a simple shape.

  • “Unresolved reference: R” in NotificationServiceExtension.kt

    The import ... .R line still points to another package. Change it to your package name, as in step 3.

  • “Unresolved reference: OneSignal”

    implementation Libs.oneSignal in app/build.gradle is still commented out, or you didn’t sync after removing the //.

  • The test notification never arrives

    Check that the App ID in OneSignal.kt matches the one in your OneSignal dashboard, that you allowed notifications on the device, and that notifications are turned on in the app’s settings.

Made by Jahir Fiquitiva. Questions? Ask in the Discord server.