A complete Android application demonstrating OneSignal push notifications with Firebase Cloud Messaging (FCM), built using Kotlin and Jetpack Compose.
- Android Studio Arctic Fox or newer
- JDK 8+
- Android device or emulator with Google Play Services
- Firebase account
- OneSignal account
-
Clone the repository
git clone https://github.com/Thogaruchesti-hemanth/NotifyHub cd OneSignalPushApp -
Configure Firebase
- Create a Firebase project at Firebase Console
- Add Android app with package name:
com.example.onesignalpushapp - Download
google-services.jsonand place it inapp/directory - Copy Firebase Server Key from Project Settings → Cloud Messaging
-
Configure OneSignal
- Create an account at OneSignal
- Create a new Android app
- Enter Firebase Server Key and Sender ID
- Copy your OneSignal App ID
-
Update the App
- Open
app/src/main/java/com/example/onesignalpushapp/OneSignalApp.kt - Replace
YOUR_ONESIGNAL_APP_IDwith your actual OneSignal App ID
- Open
-
Build and Run
- Open project in Android Studio
- Sync Gradle files
- Run on device or emulator
- ✅ Push notification registration
- ✅ Permission handling (Android 13+)
- ✅ Subscribe/Unsubscribe functionality
- ✅ User tagging system
- ✅ Real-time status updates
- ✅ Material Design 3 UI
- ✅ Dark theme support
- ✅ Notification click handling
- Language: Kotlin
- UI: Jetpack Compose + Material 3
- Push Notifications: OneSignal SDK 5.1.10
- Backend: Firebase Cloud Messaging
- Architecture: MVVM pattern ready
- Minimum SDK: 24 (Android 7.0)
- Target SDK: 34 (Android 14)
app/src/main/java/com/example/onesignalpushapp/
├── OneSignalApp.kt # Application class - OneSignal initialization
├── MainActivity.kt # Main screen with Compose UI
└── ui/theme/ # Material 3 theming
├── Color.kt
├── Theme.kt
└── Type.kt
-
From OneSignal Dashboard:
- Go to Messages → New Push
- Enter title and message
- Select audience
- Click Send
-
From API:
curl --location 'https://onesignal.com/api/v1/notifications' \ --header 'Content-Type: application/json' \ --header 'Authorization: Basic YOUR_REST_API_KEY' \ --data '{ "app_id": "YOUR_ONESIGNAL_APP_ID", "included_segments": ["All"], "contents": {"en": "Hello!"}, "headings": {"en": "Test"} }'
app/build.gradle.kts- App dependencies and configurationapp/google-services.json- Firebase configuration (not included, you need to add this)AndroidManifest.xml- Permissions and app components
// OneSignal
implementation("com.onesignal:OneSignal:5.1.10")
// Firebase
implementation(platform("com.google.firebase:firebase-bom:32.7.2"))
implementation("com.google.firebase:firebase-messaging-ktx")
implementation("com.google.firebase:firebase-analytics-ktx")
// Compose
implementation(platform("androidx.compose:compose-bom:2024.02.00"))
implementation("androidx.compose.material3:material3")-
No Push Token:
- Verify Google Play Services is installed
- Check internet connection
- Wait a few seconds and refresh
-
Notifications not appearing:
- Grant notification permission
- Check subscription status
- Verify Firebase Server Key in OneSignal
-
Build errors:
- Ensure
google-services.jsonis inapp/directory - Sync Gradle files
- Clean and rebuild project
- Ensure
// Initialize
OneSignal.initWithContext(context, appId)
// Request permission
OneSignal.Notifications.requestPermission(true)
// Subscribe/Unsubscribe
OneSignal.User.pushSubscription.optIn()
OneSignal.User.pushSubscription.optOut()
// Get User Info
val userId = OneSignal.User.pushSubscription.id
val token = OneSignal.User.pushSubscription.token
// Tagging
OneSignal.User.addTag("key", "value")
OneSignal.User.removeTag("key")
val tags = OneSignal.User.getTags()
// Listeners
OneSignal.Notifications.addClickListener { event -> }
OneSignal.Notifications.addPermissionObserver { permission -> }- Implement deep linking
- Add in-app messaging
- Create custom notification layouts
- Implement notification channels
- Add analytics tracking
- Create notification scheduling
- Add rich media notifications
- Never commit
google-services.jsonto public repositories - Add sensitive files to
.gitignore - Use environment variables for production builds
- Keep API keys secure
This project is provided as-is for educational purposes.
Feel free to submit issues and enhancement requests!
Made with ❤️ using Kotlin and Jetpack Compose