A Python library for effortlessly creating and managing Android notifications in Kivy android apps.
Supports various styles and ensures seamless integration and customization.
- Also Compatible with Android 8.0+.
- Supports including images in notifications.
- Support for multiple notification styles:
This module automatically handles:
- Permission requests for notifications
- Customizable notification channels.
This package is available on PyPI and can be installed via pip:
pip install android-notify
Prerequisites:
- Kivy
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
# Add permission for notifications
android.permissions = POST_NOTIFICATIONS
# Required dependencies (write exactly as shown, no quotation marks)
android.gradle_dependencies = androidx.core:core:1.6.0, androidx.core:core-ktx:1.15.0
android.enable_androidx = True
from android_notify import Notification
# Create a simple notification
notification = Notification(
title="Hello",
message="This is a basic notification."
)
notification.send()
The library supports multiple notification styles:
simple
- Basic notification with title and messageprogress
- Shows a progress barbig_text
- Expandable notification with long textinbox
- List-style notificationbig_picture
- Notification with a large imagelarge_icon
- Notification with a custom iconboth_imgs
- Combines big picture and large iconcustom
- For custom notification styles
from kivy.clock import Clock
notification = Notification(
title="Downloading...",
message="0% downloaded",
style="progress",
progress_max_value=100,
progress_current_value=0
)
notification.send()
Clock.schedule_once(lambda dt: notification.updateProgressBar(30, "30% downloaded"), 350)
# Image notification
notification = Notification(
title='Picture Alert!',
message='This notification includes an image.',
style="big_picture",
big_picture_path="assets/imgs/photo.png"
)
notification.send()
# Send a notification with inbox style
notification = Notification(
title='Inbox Notification',
message='Line 1\nLine 2\nLine 3',
style='inbox'
)
notification.send()
notification = Notification(
title="FabianDev_",
message="A twitter about some programming stuff",
style="large_icon",
large_icon_path="assets/imgs/profile.png"
)
notification = Notification(title="Jane Dough", message="How to use android-notify #coding #purepython")
def playVideo():
print('Playing Video')
def turnOffNoti():
print('Please Turn OFf Noti')
def watchLater():
print('Add to Watch Later')
notification.addButton(text="Play",on_release=playVideo)
notification.addButton(text="Turn Off",on_release=turnOffNoti)
notification.addButton(text="Watch Later",on_release=watchLater)
notification.send()
notification = Notification(
title="Article",
message="Long article content...",
style="big_text"
)
notification = Notification(title="Initial Title")
notification.send()
# Update title
notification.updateTitle("New Title")
# Update message
notification.updateMessage("New Message")
notification = Notification(
title="Download..",
style="progress"
)
# Update progress
notification.updateProgressBar(30, "30% downloaded")
# Remove progress bar
notification.removeProgressBar("Download Complete")
Notifications are organized into channels. You can customize the channel name and ID:
- Custom Channel Name's Gives User ability to turn on/off specific
notification = Notification(
title="Download finished",
message="How to Catch a Fish.mp4",
channel_name="Download Notifications", # Will create User-visible name "Download Notifications"
channel_id="downloads_notifications" # Optional: specify custom channel ID
)
To send a notification without sound or heads-up display:
notification = Notification(title="Silent Update")
notification.send(silent=True)
- How to Copy image to app folder
import shutil,os # These modules come packaged with python
from android.storage import app_storage_path # type: ignore -- This works only on android
app_path = os.path.join(app_storage_path(),'app')
image_path= "/storage/emulated/0/Download/profile.png"
shutil.copy(image_path, os.path.join(app_path, "profile.png"))
- Avoiding Human Error when using different notification styles
from android_notify import Notification, NotificationStyles
Notification(
title="New Photo",
message="Check out this image",
style=NotificationStyles.BIG_PICTURE,
big_picture_path="assets/imgs/photo.png"
).send()
When developing on non-Android platforms, the library provides debugging output:
# Enable logs (default is True when not on Android)
Notification.logs = True
# Create notification for testing
notification = Notification(title="Test")
notification.send()
# Will print notification properties instead of sending
- Images must be located within your app's folder
- Supported paths are relative to your app's storage path
- Example:
assets/imgs/icon.png
The library validates arguments and provides helpful error messages:
- Invalid style names will suggest the closest matching style
- Invalid arguments will list all valid options
- Missing image files will raise FileNotFoundError with the attempted path
- Only works on Android devices
- Images must be within the app's storage path
- Channel names are limited to 40 characters
- Channel IDs are limited to 50 characters
- Always handle permissions appropriately
- Use meaningful channel names for organization
- Keep progress bar updates reasonable (don't update too frequently)
- Test notifications on different Android versions
- Consider using silent notifications for frequent updates
- Enable logs during development:
Notification.logs = True
- Check channel creation with Android's notification settings
- Verify image paths before sending notifications
- Test different styles to ensure proper display
Remember to check Android's notification documentation for best practices and guidelines regarding notification frequency and content.
Feel free to open issues or submit pull requests for improvements!
Found a bug? Please open an issue on our GitHub Issues page.
- Fabian - fector101@yahoo.com
- GitHub: Android Notify Repo
- Twitter: FabianDev_
For feedback or contributions, feel free to reach out!
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.
- This Project was thoroughly Tested by the Laner Project - A application for Securely Transfering Files Wirelessly between your PC and Phone.
- Thanks to the Kivy and Pyjnius communities.
- PyPI: android-notify on PyPI
- GitHub: Source Code Repository