Skip to main content

Add your description here

Project description

Flet Local Notifications

Python Version Flet Version License

A comprehensive Flet extension that demonstrates how to manage and send notifications across multiple platforms. This project provides a simple yet powerful interface for requesting notification permissions and sending them using native APIs, with cross-platform support for Android, Windows, and Linux devices.

๐Ÿ™ Credits

Special thanks to @ITAkademi for the inspiration and guidance.

๐ŸŒ Platform Support

Platform Status Notes
Android โœ… Fully Supported Native API integration
iOS โณ Planned Cannot test currently
Windows โœ… Fully Supported Desktop notifications
macOS โœ… Fully Supported Desktop notifications
Linux โœ… Fully Supported Desktop notifications

โœจ Features

  • ๐Ÿ” Permission Management: Check and request notification permissions seamlessly
  • ๐Ÿ“ฑ Notification Sending: Send custom notifications with title and text
  • ๐Ÿค– Android Integration: Uses native Android NotificationManager via JNI
  • ๐Ÿ–ฅ๏ธ Desktop Support: Cross-platform desktop notifications
  • โฐ Scheduled Notifications: Plan notifications for future delivery
  • ๐ŸŽจ User-Friendly Interface: Simple and intuitive GUI built with Flet framework
  • ๐Ÿ”ง Advanced Configuration: Extensive customization options

๐Ÿ“‹ Requirements

  • Python 3.9+ - Modern Python features support
  • Flet framework - Cross-platform UI framework
  • Android device or emulator - For mobile testing
  • Required permissions - Configured in pyproject.toml or in AndroidManifest.xml

๐Ÿš€ Installation

pip CLI

pip install flet-local-notifications

uv CLI

uv add flet-local-notifications

๐Ÿ’ป Usage

from flet_local_notifications import (
    AndroidNotificationConfig, 
    DesktopNotificationConfig,
    FletLocalNotification,
)
from flet import *

def main(page:Page):

    noti = FletLocalNotification(page, lambda e: page.open(SnackBar(Text("Permission Acepted"))))

    async def send(e):
        await noti.send(
            AndroidNotificationConfig(
                title="Hello World",
                message="Hello"
            ),
            DesktopNotificationConfig(
                title="Hello World",
                message="Hello",
                app_name="Flet-Test",
            )
        )

    page.add(
        Button(
            text="Send", 
            on_click=lambda e: page.run_task(send, e) # <- use page.run_task() for run async functions if your main entry point is not async
        )
    )

app(target=main)

โš™๏ธ Configuration

Pyproject.toml Setup

[tool.flet]

# Permissions For The App
permissions = [
  "notification",
  "access_notification_policy", 
  "post_notifications",
  "wake_lock",
  "foreground_service"
]

[tool.flet.android.permissions]
"android.permission.ACCESS_NOTIFICATION" = true
"android.permission.POST_NOTIFICATIONS" = true
"android.permission.WAKE_LOCK" = true
"android.permission.FOREGROUND_SERVICE" = true
"android.permission.INTERNET" = true
"android.permission.RECEIVE_BOOT_COMPLETED" = true

โš ๏ธ Important Notice

For Android SDK > 35, you must manually add permissions to AndroidManifest.xml in your build project or use the custom build template.

Example 1: Manual Permission Addition

Add this line to your AndroidManifest.xml:

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

Example 2: Custom Build Template

Toml Configuration:

[tool.flet.template]
url = "gh:MasterA5/flet-build-template"
ref = "0.28.3"

Terminal Command:

flet build apk --template "gh:MasterA5/flet-build-template" --template-ref "0.28.3"

Example 3: Automatically patch AndroidManifest.xml after build (recommended)

If you are using Android SDK > 35 and prefer not to manually edit the manifest or rely on a custom build template, you can use the provided helper script.

๐Ÿ’ป Terminal

flet build apk
python scripts/fix_manifest.py

๐ŸŽฏ Application Interface

The application provides comprehensive functionality:

  1. ๐Ÿ” Check Notification Permission: Verifies if the app has notification permissions
  2. ๐Ÿ“‹ Request Notification Permission: Requests notification permissions from the user
  3. ๐Ÿ“ค Send Notification: Sends test notifications (enabled when permissions are granted)
  4. โฐ Schedule Notifications: Plan notifications for specific times
  5. ๐ŸŽจ Customize Notifications: Advanced styling and configuration options

๐Ÿ“ Project Structure

flet-local-notifications/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ flet_local_notifications/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py              # Package initialization
โ”‚   โ”‚   โ”œโ”€โ”€ core.py                  # Core notification logic
โ”‚   โ”‚   โ”œโ”€โ”€ flet_local_notifications.py  # Main notification class
โ”‚   โ”‚   โ”œโ”€โ”€ android/                 # Android-specific implementations
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ AndroidNotification.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ android_types.py
โ”‚   โ”‚   โ”œโ”€โ”€ desktop/                 # Desktop-specific implementations
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ DesktopNotification.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ desktop_types.py
โ”‚   โ”‚   โ””โ”€โ”€ schedule/                # Scheduling functionality
โ”‚   โ”‚       โ””โ”€โ”€ schedule_types.py
โ”‚   โ””โ”€โ”€ main.py                      # Main application entry point
โ”œโ”€โ”€ pyproject.toml                   # Project configuration and dependencies
โ”œโ”€โ”€ README.md                        # This file
โ”œโ”€โ”€ README_MEJORADO.md              # Enhanced documentation
โ”œโ”€โ”€ LICENSE                          # MIT License
โ””โ”€โ”€ .gitignore                       # Git ignore file

๐Ÿ”ง Key Components

FletLocalNotification Class

The main class that handles cross-platform notification functionality:

  • Platform Detection: Automatically detects Android vs Desktop environments
  • Permission Handling: Manages notification permissions across platforms
  • Unified API: Single interface for multiple platforms
  • Async Support: Full asynchronous implementation

AndroidNotification Class

Located in flet_local_notifications/android/AndroidNotification.py:

  • Native Integration: Uses Android NotificationManager via JNI
  • Channel Management: Creates and manages notification channels
  • Advanced Features: Progress bars, buttons, images, and more
  • Permission Requests: Handles Android runtime permissions

DesktopNotification Class

Located in flet_local_notifications/desktop/DesktopNotification.py:

  • Cross-Platform: Windows, macOS, and Linux support
  • Native Notifications: Uses system notification services
  • Interactive Elements: Buttons, reply fields, and callbacks
  • Custom Styling: Icons, sounds, and attachments

๐Ÿ“ฆ Dependencies

Core Dependencies

  • flet==0.28.3: Main UI framework
  • desktop-notifier: Desktop notification management
  • android-notify==1.60.8.dev0: Android notification support

๐Ÿ” Android Permissions

The app requests the following permissions (configured in pyproject.toml):

Permission Purpose
notification Basic notification access
access_notification_policy Access to notification policies
post_notifications Ability to post notifications
wake_lock Keep device awake for notifications
foreground_service Run as foreground service
INTERNET Network access (if needed, be deafult in a flet build template)
RECEIVE_BOOT_COMPLETED Auto-start on boot

๐Ÿš€ Quick Start Examples

๐Ÿ“ฑ | ๐Ÿ’ป Basic Notification

import flet as ft
from flet_local_notifications import FletLocalNotification, AndroidNotificationConfig, DesktopNotificationConfig

async def main(page: ft.Page):
    notifier = FletLocalNotification(page)
    
    android_config = AndroidNotificationConfig(
        title="Hello World!",
        message="This is a test notification"
    )
    
    desktop_config = DesktopNotificationConfig(
        title="Hello World!", 
        message="This is a test notification"
    )
    
    await notifier.send(android_config, desktop_config)

ft.app(target=main)

๐Ÿ“ฑ | ๐Ÿ’ป -> โฐ Scheduled Notification

from datetime import datetime, timedelta
from flet_local_notifications import ScheduleNotificationConfig

async def main(page: ft.Page):
    notifier = FletLocalNotification(page)
    
    # Schedule for 5 minutes from now
    schedule_config = ScheduleNotificationConfig(
        notify_time=datetime.now() + timedelta(minutes=5)
    )
    
    # ... notification configs ...
    await notifier.schedule(schedule_config, android_config, desktop_config)

๐Ÿ”ฎ Future Improvements

  • iOS Support: Add iOS notification capabilities
  • Notification Groups: Implement notification categories
  • Advanced Actions: Enhanced notification interactions
  • Rich Media: Audio, video, and interactive content
  • Cloud Sync: Cross-device notification synchronization
  • Analytics: Notification engagement tracking

๐Ÿ“ Notes

  • Permission Requirements: Notification functionality requires proper permissions to be granted by the user
  • Native APIs: The app uses native platform APIs for reliable notification delivery
  • Platform Differences: Some features may vary between platforms due to OS limitations
  • Testing: Always test on target platforms before deployment

๐Ÿค Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Guidelines

  • Follow PEP 8 style guidelines
  • Add type hints for new functions
  • Include docstrings for public APIs
  • Add tests for new features
  • Update documentation as needed

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘จโ€๐Ÿ’ป Author

MasterA5 - Creator and Maintainer - GitHub Profile

๐Ÿ™ Acknowledgments

๐Ÿ†˜ Support

If you encounter any issues or have questions:

  1. Check the Issues page
  2. Create a new issue with detailed information
  3. Include your platform, Python version, and minimal reproduction code
  4. Provide screenshots or error messages when applicable

โญ Star this repository to stay updated with new features and improvements!

๐Ÿ“ข Share this project with other Flet developers who might find it useful!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flet_local_notifications-1.0.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flet_local_notifications-1.0.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file flet_local_notifications-1.0.0.tar.gz.

File metadata

File hashes

Hashes for flet_local_notifications-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1fa1bb2efd4f233b5a8d5cca451a93c241f4d569f393864ed250202ede8d28a4
MD5 f0620ee0f93f95e4eff7834558a79879
BLAKE2b-256 325f231b98db02604143a84d384573d24b885523693f8ec4036e0b9a1c29fea8

See more details on using hashes here.

File details

Details for the file flet_local_notifications-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flet_local_notifications-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 557bf317e6c9cd92f5521647c32269e790646398d83321f2eb94ecd4884c15f8
MD5 932edc3c2420197218a1e340efb9224f
BLAKE2b-256 6446a03def4f7f66c7450b98b81ec34c6e230d73ef091ff2d1dbc0744499f6b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page