https://github.com/guhan-sensam/android-notification-in-python
A comprehensive guide into creating notification on android using python
https://github.com/guhan-sensam/android-notification-in-python
android java notifications pyjnius python
Last synced: about 1 month ago
JSON representation
A comprehensive guide into creating notification on android using python
- Host: GitHub
- URL: https://github.com/guhan-sensam/android-notification-in-python
- Owner: Guhan-SenSam
- Created: 2021-06-17T18:15:21.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-16T08:44:27.000Z (over 3 years ago)
- Last Synced: 2025-04-18T20:50:07.523Z (about 1 month ago)
- Topics: android, java, notifications, pyjnius, python
- Language: Python
- Homepage:
- Size: 39.1 KB
- Stars: 26
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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 apkThere 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
```3. 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
```
4. After this make sure you run `buildozer android clean` and then you can recompile your app.