Skip to content

thomasjbarrett82/ExtraLifeNotifications

Repository files navigation

Extra Life Notifications

An app that counts every phone notification and plays a custom sound every N notifications (default: 100).

Requirements

  • Android 14 (API level 34) or higher
  • Notification Access permission
  • Foreground Service permission
  • Storage Access Framework (for custom sound files)

Permissions

The app requires the following permissions:

  1. Notification Access: Required to listen to and count notifications
  2. POST_NOTIFICATIONS: Required to show the foreground service notification
  3. FOREGROUND_SERVICE: Required to run the notification listener reliably
  4. FOREGROUND_SERVICE_SPECIAL_USE: Specific foreground service type for notification listening

Installation

  1. Clone this repository
  2. Open the project in Android Studio
  3. Sync Gradle files
  4. Build and run on an Android 14+ device or emulator
git clone https://github.com/thomasjbarrett82/ExtraLifeNotifications.git
cd ExtraLifeNotifications
./gradlew build

Usage

  1. First Launch:

    • The app will request necessary permissions
    • Grant notification access when prompted (this will open Android settings)
    • Grant notification permission when prompted
  2. Configure Settings:

    • Set the notification interval (default is 100)
    • Optionally select a custom sound file from your device
  3. Monitor Notifications:

    • The app will run in the background and count all notifications
    • Every N notifications, it will play the "extra life" sound
    • View the current count on the main screen
  4. Status Indicators:

    • ✓ Active and Running: All permissions granted, service is monitoring
    • ⚠️ Notification Access Required: Need to grant notification listener access
    • ⚠️ Notification Permission Required: Need to grant POST_NOTIFICATIONS permission

Project Structure

ExtraLifeNotifications/
├── app/
│   ├── src/
│   │   └── main/
│   │       ├── java/com/extralifenotifications/
│   │       │   ├── MainActivity.kt                    # Main UI activity
│   │       │   └── NotificationListenerService.kt    # Background service
│   │       ├── res/
│   │       │   ├── layout/
│   │       │   │   └── activity_main.xml             # Main UI layout
│   │       │   ├── values/
│   │       │   │   ├── strings.xml
│   │       │   │   ├── colors.xml
│   │       │   │   └── themes.xml
│   │       │   ├── drawable/
│   │       │   │   └── ic_notification.xml           # Notification icon
│   │       │   ├── raw/
│   │       │   │   └── milestone_sound.mp3           # Default sound
│   │       │   └── mipmap-*/                         # Launcher icons
│   │       └── AndroidManifest.xml
│   ├── build.gradle
│   └── proguard-rules.pro
├── build.gradle
├── settings.gradle
└── gradle.properties

Architecture

MainActivity

  • Handles UI and user interactions
  • Manages permissions requests
  • Displays notification count and status
  • Allows configuration of interval and custom sound
  • Uses SharedPreferences for persistent storage

NotificationListenerService

  • Extends Android's NotificationListenerService
  • Runs as a foreground service for reliability
  • Counts incoming notifications (excluding its own)
  • Plays milestone sounds at configured intervals
  • Automatically reconnects if disconnected

SharedPreferences Keys

  • notification_count: Current notification count
  • notification_interval: Milestone interval (default: 100)
  • custom_sound_uri: URI of custom sound file (if selected)

Technical Details

Android Best Practices Implemented

  1. Foreground Service: Ensures the notification listener isn't killed by Android's battery optimization
  2. SharedPreferences: Persists app state across restarts and reboots
  3. Storage Access Framework: Modern way to access user files with proper permissions
  4. Material Design 3: Modern, accessible UI components
  5. Kotlin: Modern, type-safe language with null safety
  6. ViewBinding: Type-safe view access
  7. Notification Channels: Required for Android O+
  8. Runtime Permissions: Proper permission handling for Android 13+

Sound Playback

  • Uses MediaPlayer for audio playback
  • Releases resources properly after playback
  • Handles both default (raw resource) and custom (SAF URI) sounds
  • Includes error handling for invalid sound files

Service Reliability

  • Implements onListenerConnected() and onListenerDisconnected()
  • Uses requestRebind() to automatically reconnect (Android N+)
  • Foreground service notification prevents service termination
  • Updates foreground notification with current count

Customization

Changing Default Sound

Replace app/src/main/res/raw/milestone_sound.mp3 with your own sound file.

Changing Default Interval

Modify the default value in MainActivity.kt:

val savedInterval = sharedPreferences.getInt(PREF_NOTIFICATION_INTERVAL, 100) // Change 100

Changing App Colors

Edit app/src/main/res/values/colors.xml and themes.xml.

Troubleshooting

Service Not Counting

  1. Ensure notification access is granted in Android Settings
  2. Check that the app has POST_NOTIFICATIONS permission
  3. Verify the foreground service notification is visible
  4. Restart the app after granting permissions

Sound Not Playing

  1. Check device volume is not muted
  2. Verify the custom sound file (if selected) is valid
  3. Try resetting to default sound
  4. Check Android's Do Not Disturb settings

Count Resets

  • The count is saved in SharedPreferences and should persist
  • If count resets, check if app data was cleared
  • Verify SharedPreferences are not being cleared by other apps or tools

Building for Release

  • Update version in app/build.gradle:
versionCode 2
versionName "1.1"
  • Generate signed APK:
./gradlew assembleRelease
  • Find APK at: app/build/outputs/apk/release/app-release.apk

License

This project is provided as-is for educational and personal use.

Contributing

Feel free to submit issues and pull requests.

Acknowledgments

  • Built with Android Studio
  • Uses Material Design 3 components
  • Kotlin programming language
  • Written with AI assistance (Claude and Gemini)
  • Default sound from IndyArts

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages