Skip to content

Thogaruchesti-hemanth/NotifyHub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OneSignal Push Notification App

A complete Android application demonstrating OneSignal push notifications with Firebase Cloud Messaging (FCM), built using Kotlin and Jetpack Compose.

🚀 Quick Start

Prerequisites

  • Android Studio Arctic Fox or newer
  • JDK 8+
  • Android device or emulator with Google Play Services
  • Firebase account
  • OneSignal account

Setup Steps

  1. Clone the repository

    git clone https://github.com/Thogaruchesti-hemanth/NotifyHub
    cd OneSignalPushApp
  2. Configure Firebase

    • Create a Firebase project at Firebase Console
    • Add Android app with package name: com.example.onesignalpushapp
    • Download google-services.json and place it in app/ directory
    • Copy Firebase Server Key from Project Settings → Cloud Messaging
  3. Configure OneSignal

    • Create an account at OneSignal
    • Create a new Android app
    • Enter Firebase Server Key and Sender ID
    • Copy your OneSignal App ID
  4. Update the App

    • Open app/src/main/java/com/example/onesignalpushapp/OneSignalApp.kt
    • Replace YOUR_ONESIGNAL_APP_ID with your actual OneSignal App ID
  5. Build and Run

    • Open project in Android Studio
    • Sync Gradle files
    • Run on device or emulator

✨ Features

  • ✅ 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

🏗️ Tech Stack

  • 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 Structure

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

🧪 Testing

Send Test Notification

  1. From OneSignal Dashboard:

    • Go to Messages → New Push
    • Enter title and message
    • Select audience
    • Click Send
  2. 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"}
    }'

🔧 Configuration Files

  • app/build.gradle.kts - App dependencies and configuration
  • app/google-services.json - Firebase configuration (not included, you need to add this)
  • AndroidManifest.xml - Permissions and app components

📋 Dependencies

// 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")

🐛 Troubleshooting

Common Issues

  1. No Push Token:

    • Verify Google Play Services is installed
    • Check internet connection
    • Wait a few seconds and refresh
  2. Notifications not appearing:

    • Grant notification permission
    • Check subscription status
    • Verify Firebase Server Key in OneSignal
  3. Build errors:

    • Ensure google-services.json is in app/ directory
    • Sync Gradle files
    • Clean and rebuild project

📚 API Reference

OneSignal Methods Used

// 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 -> }

🎯 Next Steps

  • Implement deep linking
  • Add in-app messaging
  • Create custom notification layouts
  • Implement notification channels
  • Add analytics tracking
  • Create notification scheduling
  • Add rich media notifications

🔐 Security

  • Never commit google-services.json to public repositories
  • Add sensitive files to .gitignore
  • Use environment variables for production builds
  • Keep API keys secure

📄 License

This project is provided as-is for educational purposes.

🤝 Contributing

Feel free to submit issues and enhancement requests!

📞 Support


Made with ❤️ using Kotlin and Jetpack Compose