Skip to content

A comprehensive guide into creating notification on android using python

Notifications You must be signed in to change notification settings

Guhan-SenSam/Android-Notification-in-Python

Repository files navigation

Android Notification in Python

This is a guide into how to create various reminders on android using python.This repo was intended for people who use kivy and buildozer for python app development. But its concepts can be applied for any other use case.

There are various modules already available that offer this functionality but due to the need to make these flexible and able to adapt to a large number of use cases they lack some necessary features.

Thus here I will go into how to create different types of reminders in android using java code.But don't worry.We will write most of the code in python and use something called pyjnius to wrap our python code into java code.

Note: Some operations require you to write some java code. Just learn a little bit of java basics and you will understand the code easily

Getting Started

Before you proceed any further there are some things that you have to setup before you create any type of notification.

Note: I am assuming you are using buildozer to compile your python code into an apk

There are two ways to send notification in android. The first way is the old way and requires you to manually code compatibility in for older versions of android. The second way is the newer method and automatically handles backward compatibility for you. We will be using the second method through out this entire repo.

  1. Clone and install the latest version of buildozer from here (https://buildozer.readthedocs.io/en/latest/)

  2. change the branch for p4a in your buildozer spec file

# (str) python-for-android branch to use, defaults to master
p4a.branch = develop
  1. We will be using the NotificationCompatBuilder and NotificationCompat through out this repo to make notification. For this you must enable androidx support in your app.

    To do this first go to your buildozer.spec file and change these values to below values:

    # (list) Gradle dependencies to add
    android.gradle_dependencies = androidx.work:work-runtime:2.2.0
    
    # (bool) Enable AndroidX support. Enable when 'android.gradle_dependencies'
    # contains an 'androidx' package, or any package from Kotlin source.
    # android.enable_androidx requires android.api >= 28
    android.enable_androidx = True
    

    As you might have noticed this will only work if you set your target api for somethin equal to or greater than 28.(This doesnt mean your app will not work on older android devices.It just means the app will be compiled to work best on whatever api you have set)

    # (int) Target Android API, should be as high as possible.
    android.api = 30
    
  2. After this make sure you run buildozer android clean and then you can recompile your app.

About

A comprehensive guide into creating notification on android using python

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published