Skip to main content

A Python package that simplifies creating Android notifications in Kivy and Flet apps.

Project description


Android-Notify

Android Notify is a Python library for effortlessly creating and managing Android notifications in Kivy and Flet apps.

Supports various styles and ensures seamless integration, customization and Pythonic APIs.

Features

  • Multiple Notification Styles: Support for various notification styles including:

    • Simple text notifications
    • Progress bar notifications (determinate and indeterminate)
    • Large icon notifications
    • Big picture notifications
    • Combined image styles
    • Custom notification Icon - images section
    • Big text notifications
    • Inbox-style notifications
    • Colored texts and Icons
  • Rich Functionality:

    • Add action buttons with custom callbacks
    • Update notification content dynamically
    • Manage progress bars with fine-grained control
    • Custom notification channels for Android 8.0+ (Creating and Deleting)
    • Silent notifications
    • Persistent notifications
    • Click handlers and callbacks
    • Cancel Notifications

Quick Start

from android_notify import Notification

# Simple notification
Notification(
    title="Hello",
    message="This is a basic notification."
).send()

Sample Image:
basic notification img sample

Installation

Kivy apps:

In your buildozer.spec file, ensure you include the following:

# Add pyjnius so ensure it's packaged with the build
requirements = python3, kivy, pyjnius, android-notify==1.61.3.dev0
# Add permission for notifications
android.permissions = POST_NOTIFICATIONS
Flet apps:

In your pyproject.toml file, ensure you include the following:

[tool.flet.android]
dependencies = [
  "pyjnius","android-notify==1.61.3.dev0"
]

[tool.flet.android.permission]
"android.permission.POST_NOTIFICATIONS" = true
On Pydroid 3

On the pydroid 3 mobile app for running python code you can test some features.

  • In pip section where you're asked to insert Libary name paste android-notify==1.61.3.dev0
  • Minimal working example
# Testing with `android-notify==1.61.3.dev0` on pydroid
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from android_notify import Notification
from android_notify.core import asks_permission_if_needed


class AndroidNotifyDemoApp(App):
    def build(self):
        layout = BoxLayout(orientation='vertical', spacing=10, padding=20)
        layout.add_widget(Button(
            text="Ask Notification Permission",
            on_release=self.request_permission
        ))
        layout.add_widget(Button(
            text="Send Notification",
            on_release=self.send_notification
        ))
        return layout

    def request_permission(self, *args):
        asks_permission_if_needed(legacy=True)

    def send_notification(self, *args):
        Notification(
            title="Hello from Android Notify",
            message="This is a basic notification.",
            channel_id="android_notify_demo",
            channel_name="Android Notify Demo"
        ).send()


if __name__ == "__main__":
    AndroidNotifyDemoApp().run()
Desktop

For IDE IntelliSense Can be installed via pip install:

pip install android_notify
android-notify -v

Documentation

For Dev Version use

requirements = python3, kivy, pyjnius, https://github.com/Fector101/android_notify/archive/without-androidx.zip
To talk to BroadCast Listener From Buttons
  • Make things happen without being in your app
from android_notify import Notification
notification = Notification(title="Receiver Notification")
notification.addButton(text="Stop", receiver_name="CarouselReceiver", action="ACTION_STOP")
notification.addButton(text="Skip", receiver_name="CarouselReceiver", action="ACTION_SKIP")

You can use this wiki as a guide create a broadcast listener

To use colored text in your notifications
  • Copy the res folder to your app path.
  • Lastly in your buildozer.spec file
    Add source.include_exts = xml and android.add_resources = # path you pasted
# Use Hex Code to be Safe
n = Notification(title="Title and Message Color", message="Testing",title_color="red")
n.send()
To use Custom Sounds

Option 1: Audio files bundled in res/raw

  • Put audio files in res/raw folder,
  • Then from buildozer.spec point to res folder android.add_resources = res
  • and includes it's format source.include_exts = wav.

Lastly From the code

# Create a custom notification channel with a unique sound resource for android 8+
Notification.createChannel(
    id="weird_sound_tester",
    name="Weird Sound Tester",
    description="A test channel for custom sounds from the res/raw folder.",
    res_sound_name="sneeze" # file name without .wav or .mp3
)

# Send a notification through the created channel
n=Notification(
    title="Custom Sound Notification",
    message="This tests playback of a custom sound (sneeze.wav) stored in res/raw.",
    channel_id="weird_sound_tester" # important tells notification to use right channel
)
n.setSound("sneeze")# for android 7 below 
n.send()

Option 2: Local file path or URI (sound_path)

You can use a local audio file, a content://, file://, or android.resource:// URI directly:

# Using a local file path
Notification.createChannel(
    id="local_sound",
    name="Local Sound",
    sound_path="/storage/emulated/0/Download/alert.mp3"
)

# Using a content URI (e.g., from media store)
Notification.createChannel(
    id="uri_sound",
    name="URI Sound",
    sound_path="content://media/external/audio/media/123"
)

# Send notification with custom sound path
n = Notification(
    title="Custom Sound",
    message="Playing from local path",
    channel_id="local_sound"
)
n.setSound(sound_path="/storage/emulated/0/Download/alert.mp3")
n.send()

Private files (e.g., in app's data/ directory) are automatically copied to external storage before playing.

Vibrate feature
# buildozer.spec
android.permissions = VIBRATE
Notification.createChannel(id='shake', name="Shake Passage", vibrate=True)

n=Notification(title='Vibrate',channel_id='shake')
n.setVibrate() # for less than android 8
n.fVibrate() # To Force Vibrate (when user turned off in settings)
n.send()
Add Data to Notification
  • NotificationHandler.data_object returns a dict of data in the clicked notification
  • setData can also be called after send to change data_object stored
  • Use name if value is constant Notification(name="change page")
from android_notify import Notification, NotificationHandler

    def build(self):
        notification = Notification(title="Hello")
        notification.setData({"next wallpaper path": "test.jpg"})
        notification.send()

    def on_start(self):
        notification_data = NotificationHandler.data_object  # {"next wallpaper path": "test.jpg",...}
        print(notifcation_data)

    def on_resume(self):
        notification_data = NotificationHandler.data_object  # {"next wallpaper path": "test.jpg",...}
        print(notifcation_data)

For full documentation, examples, and advanced usage, API reference visit the documentation

☕ Support the Project

If you find this project helpful, consider buying me a coffee! 😊
Or Giving it a star on 🌟 GitHub Your support helps maintain and improve the project.

Buy Me A Coffee

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

android_notify-1.61.3.dev0.tar.gz (96.2 kB view details)

Uploaded Source

Built Distribution

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

android_notify-1.61.3.dev0-py3-none-any.whl (108.1 kB view details)

Uploaded Python 3

File details

Details for the file android_notify-1.61.3.dev0.tar.gz.

File metadata

  • Download URL: android_notify-1.61.3.dev0.tar.gz
  • Upload date:
  • Size: 96.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for android_notify-1.61.3.dev0.tar.gz
Algorithm Hash digest
SHA256 f69c86104d1a02982cb8e32ef08f22fa53b2c5df5166be6d5cedc50aba9c4e4d
MD5 bc7aa3e1960236c0eda46c9a2b88cef5
BLAKE2b-256 083fe8b24c6b4e208d5964816706fe9d4cea8da57a65a5c80873e6734d341977

See more details on using hashes here.

Provenance

The following attestation bundles were made for android_notify-1.61.3.dev0.tar.gz:

Publisher: publish.yml on Fector101/android_notify

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file android_notify-1.61.3.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for android_notify-1.61.3.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0c6dde10bf8d72b79cf79bf6aeda00cdac067fad9fca45d423937ed6fe44825
MD5 db19aad72730e7d76123632b750d49be
BLAKE2b-256 d621409161ca5ef0ecf507260631bd65f6f9c67d29d777feb5a0042fbb37971d

See more details on using hashes here.

Provenance

The following attestation bundles were made for android_notify-1.61.3.dev0-py3-none-any.whl:

Publisher: publish.yml on Fector101/android_notify

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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