Skip to content

A Python package that simplifies sending Android notifications with support of various styles

Notifications You must be signed in to change notification settings

Fector101/android_notify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


Android-Notifiy

A Python library for effortlessly creating and managing Android notifications in Kivy android apps.

Supports various styles and ensures seamless integration and customization.

Features

This module automatically handles:

  • Permission requests for notifications
  • Customizable notification channels.

Installation

This package is available on PyPI and can be installed via pip:

pip install android-notify

Dependencies

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

Basic Usage

from android_notify import Notification

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

Sample Image:
basic notification img sample

Notification Styles

The library supports multiple notification styles:

  1. simple - Basic notification with title and message
  2. progress - Shows a progress bar
  3. big_text - Expandable notification with long text
  4. inbox - List-style notification
  5. big_picture - Notification with a large image
  6. large_icon - Notification with a custom icon
  7. both_imgs - Combines big picture and large icon
  8. custom - For custom notification styles

Style Examples

Progress Bar notification

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)

Sample Image: progress img sample

Notification with an Image (Big Picture Style)

# 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()

Sample Image: big_picture img sample

Inbox Notification Style

# Send a notification with inbox style
notification = Notification(
    title='Inbox Notification',
    message='Line 1\nLine 2\nLine 3',
    style='inbox'
)
notification.send()

Sample Image: Inbox Notification sample

Notification with an Image (Large Icon Style)

notification = Notification(
    title="FabianDev_",
    message="A twitter about some programming stuff",
    style="large_icon",
    large_icon_path="assets/imgs/profile.png"
)

Sample Image:
large_icon img sample

Notification with Buttons

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()

Sample Image:
btns img sample

Big text notification (Will Display as normal text if Device dosen't support)

notification = Notification(
    title="Article",
    message="Long article content...",
    style="big_text"
)

Advanced Features

Updating Notifications

notification = Notification(title="Initial Title")
notification.send()

# Update title
notification.updateTitle("New Title")

# Update message
notification.updateMessage("New Message")

Progress Bar Management

notification = Notification(
    title="Download..",
    style="progress"
)

# Update progress
notification.updateProgressBar(30, "30% downloaded")

# Remove progress bar
notification.removeProgressBar("Download Complete")

Channel Management

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
)

Sample Image:
channels img sample

Silent Notifications

To send a notification without sound or heads-up display:

notification = Notification(title="Silent Update")
notification.send(silent=True)

Assist

  • 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()

Development Mode

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

Image Requirements

  • Images must be located within your app's folder
  • Supported paths are relative to your app's storage path
  • Example: assets/imgs/icon.png

Error Handling

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

Limitations

  1. Only works on Android devices
  2. Images must be within the app's storage path
  3. Channel names are limited to 40 characters
  4. Channel IDs are limited to 50 characters

Best Practices

  1. Always handle permissions appropriately
  2. Use meaningful channel names for organization
  3. Keep progress bar updates reasonable (don't update too frequently)
  4. Test notifications on different Android versions
  5. Consider using silent notifications for frequent updates

Debugging Tips

  1. Enable logs during development: Notification.logs = True
  2. Check channel creation with Android's notification settings
  3. Verify image paths before sending notifications
  4. Test different styles to ensure proper display

Remember to check Android's notification documentation for best practices and guidelines regarding notification frequency and content.

Contribution

Feel free to open issues or submit pull requests for improvements!

Reporting Issues

Found a bug? Please open an issue on our GitHub Issues page.

Author

For feedback or contributions, feel free to reach out!


β˜• 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

Acknowledgments

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

🌐 Links