android-notify 1.1__py3-none-any.whl → 1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of android-notify might be problematic. Click here for more details.
- android_notify/__init__.py +3 -0
- android_notify/core.py +82 -110
- android_notify/styles.py +13 -3
- android_notify/sword.py +375 -0
- android_notify-1.3.dist-info/METADATA +350 -0
- android_notify-1.3.dist-info/RECORD +9 -0
- {android_notify-1.1.dist-info → android_notify-1.3.dist-info}/WHEEL +1 -1
- android_notify-1.1.dist-info/METADATA +0 -140
- android_notify-1.1.dist-info/RECORD +0 -8
- {android_notify-1.1.dist-info → android_notify-1.3.dist-info}/top_level.txt +0 -0
android_notify/__init__.py
CHANGED
android_notify/core.py
CHANGED
|
@@ -1,24 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
from jnius import autoclass,cast
|
|
1
|
+
""" Non-Advanced Stuff """
|
|
3
2
|
import random
|
|
4
3
|
import os
|
|
4
|
+
from jnius import autoclass,cast
|
|
5
5
|
|
|
6
|
+
ON_ANDROID = False
|
|
7
|
+
try:
|
|
8
|
+
# Get the required Java classes
|
|
9
|
+
PythonActivity = autoclass('org.kivy.android.PythonActivity')
|
|
10
|
+
NotificationChannel = autoclass('android.app.NotificationChannel')
|
|
11
|
+
String = autoclass('java.lang.String')
|
|
12
|
+
Intent = autoclass('android.content.Intent')
|
|
13
|
+
PendingIntent = autoclass('android.app.PendingIntent')
|
|
14
|
+
context = PythonActivity.mActivity # Get the app's context
|
|
15
|
+
BitmapFactory = autoclass('android.graphics.BitmapFactory')
|
|
16
|
+
BuildVersion = autoclass('android.os.Build$VERSION')
|
|
17
|
+
ON_ANDROID=True
|
|
18
|
+
except Exception as e:
|
|
19
|
+
print('This Package Only Runs on Android !!! ---> Check "https://github.com/Fector101/android_notify/" to see design patterns and more info.')
|
|
20
|
+
|
|
21
|
+
if ON_ANDROID:
|
|
22
|
+
try:
|
|
23
|
+
NotificationManagerCompat = autoclass('androidx.core.app.NotificationManagerCompat')
|
|
24
|
+
NotificationCompat = autoclass('androidx.core.app.NotificationCompat')
|
|
25
|
+
|
|
26
|
+
# Notification Design
|
|
27
|
+
NotificationCompatBuilder = autoclass('androidx.core.app.NotificationCompat$Builder')
|
|
28
|
+
NotificationCompatBigTextStyle = autoclass('androidx.core.app.NotificationCompat$BigTextStyle')
|
|
29
|
+
NotificationCompatBigPictureStyle = autoclass('androidx.core.app.NotificationCompat$BigPictureStyle')
|
|
30
|
+
NotificationCompatInboxStyle = autoclass('androidx.core.app.NotificationCompat$InboxStyle')
|
|
31
|
+
except Exception as e:
|
|
32
|
+
print("""
|
|
33
|
+
Dependency Error: Add the following in buildozer.spec:
|
|
34
|
+
* android.gradle_dependencies = androidx.core:core-ktx:1.15.0, androidx.core:core:1.6.0
|
|
35
|
+
* android.enable_androidx = True
|
|
36
|
+
* android.permissions = POST_NOTIFICATIONS
|
|
37
|
+
""")
|
|
6
38
|
|
|
7
39
|
def asks_permission_if_needed():
|
|
8
40
|
"""
|
|
9
41
|
Ask for permission to send notifications if needed.
|
|
10
42
|
"""
|
|
11
|
-
# Get the required Java classes
|
|
12
43
|
from android.permissions import request_permissions, Permission,check_permission # type: ignore
|
|
13
|
-
|
|
14
|
-
def check_permissions(permissions):
|
|
15
|
-
for permission in permissions:
|
|
16
|
-
if check_permission(permission) != True:
|
|
17
|
-
return False
|
|
18
|
-
return True
|
|
19
44
|
|
|
20
45
|
permissions=[Permission.POST_NOTIFICATIONS]
|
|
21
|
-
if
|
|
46
|
+
if not all(check_permission(p) for p in permissions):
|
|
22
47
|
request_permissions(permissions)
|
|
23
48
|
|
|
24
49
|
def get_image_uri(relative_path):
|
|
@@ -28,62 +53,48 @@ def get_image_uri(relative_path):
|
|
|
28
53
|
:return: Absolute URI java Object (e.g., 'file:///path/to/file.png').
|
|
29
54
|
"""
|
|
30
55
|
from android.storage import app_storage_path # type: ignore
|
|
31
|
-
# print("app_storage_path()",app_storage_path())
|
|
32
56
|
|
|
33
57
|
output_path = os.path.join(app_storage_path(),'app', relative_path)
|
|
34
58
|
# print(output_path,'output_path') # /data/user/0/org.laner.lan_ft/files/app/assets/imgs/icon.png
|
|
35
|
-
|
|
59
|
+
|
|
60
|
+
if not os.path.exists(output_path):
|
|
61
|
+
raise FileNotFoundError(f"Image not found at path: {output_path}")
|
|
62
|
+
|
|
36
63
|
Uri = autoclass('android.net.Uri')
|
|
37
64
|
return Uri.parse(f"file://{output_path}")
|
|
38
65
|
|
|
39
|
-
|
|
66
|
+
|
|
67
|
+
def send_notification(
|
|
68
|
+
title:str,
|
|
69
|
+
message:str,
|
|
70
|
+
style=None,
|
|
71
|
+
img_path=None,
|
|
72
|
+
channel_name="Default Channel",
|
|
73
|
+
channel_id:str="default_channel"
|
|
74
|
+
):
|
|
40
75
|
"""
|
|
41
76
|
Send a notification on Android.
|
|
42
77
|
|
|
43
78
|
:param title: Title of the notification.
|
|
44
79
|
:param message: Message body.
|
|
45
|
-
:param style: Style of the notification ('big_text', 'big_picture', 'inbox').
|
|
46
|
-
:param
|
|
47
|
-
:param channel_id: Notification channel ID.
|
|
80
|
+
:param style: Style of the notification ('big_text', 'big_picture', 'inbox', 'large_icon').
|
|
81
|
+
:param img_path: Path to the image resource.
|
|
82
|
+
:param channel_id: Notification channel ID.(Default is lowercase channel name arg in lowercase)
|
|
48
83
|
"""
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
String = autoclass('java.lang.String')
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
NotificationManagerCompat = autoclass('androidx.core.app.NotificationManagerCompat')
|
|
59
|
-
NotificationCompat = autoclass('androidx.core.app.NotificationCompat')
|
|
60
|
-
|
|
61
|
-
# Notification Design
|
|
62
|
-
NotificationCompatBuilder = autoclass('androidx.core.app.NotificationCompat$Builder')
|
|
63
|
-
NotificationCompatBigTextStyle = autoclass('androidx.core.app.NotificationCompat$BigTextStyle')
|
|
64
|
-
# NotificationCompatBigTextStyle = autoclass('android.app.Notification$BigTextStyle')
|
|
65
|
-
|
|
66
|
-
NotificationCompatBigPictureStyle = autoclass('androidx.core.app.NotificationCompat$BigPictureStyle')
|
|
67
|
-
NotificationCompatInboxStyle = autoclass('androidx.core.app.NotificationCompat$InboxStyle')
|
|
68
|
-
BitmapFactory = autoclass('android.graphics.BitmapFactory')
|
|
69
|
-
BuildVersion = autoclass('android.os.Build$VERSION')
|
|
70
|
-
PendingIntent = autoclass('android.app.PendingIntent')
|
|
71
|
-
Intent = autoclass('android.content.Intent')
|
|
72
|
-
|
|
73
|
-
# Get the app's context and notification manager
|
|
74
|
-
context = PythonActivity.mActivity
|
|
84
|
+
if not ON_ANDROID:
|
|
85
|
+
print('This Package Only Runs on Android !!! ---> Check "https://github.com/Fector101/android_notify/" for Documentation.')
|
|
86
|
+
return
|
|
87
|
+
asks_permission_if_needed()
|
|
88
|
+
channel_id=channel_name.replace(' ','_').lower().lower() if not channel_id else channel_id
|
|
89
|
+
# Get notification manager
|
|
75
90
|
notification_manager = context.getSystemService(context.NOTIFICATION_SERVICE)
|
|
76
91
|
|
|
92
|
+
# importance= autoclass('android.app.NotificationManager').IMPORTANCE_HIGH # also works #NotificationManager.IMPORTANCE_DEFAULT
|
|
77
93
|
importance= NotificationManagerCompat.IMPORTANCE_HIGH #autoclass('android.app.NotificationManager').IMPORTANCE_HIGH also works #NotificationManager.IMPORTANCE_DEFAULT
|
|
78
94
|
|
|
79
95
|
# Notification Channel (Required for Android 8.0+)
|
|
80
96
|
if BuildVersion.SDK_INT >= 26:
|
|
81
|
-
|
|
82
|
-
channel = NotificationChannel(
|
|
83
|
-
channel_id,
|
|
84
|
-
"Default Channel",
|
|
85
|
-
importance
|
|
86
|
-
)
|
|
97
|
+
channel = NotificationChannel(channel_id, channel_name,importance)
|
|
87
98
|
notification_manager.createNotificationChannel(channel)
|
|
88
99
|
|
|
89
100
|
# Build the notification
|
|
@@ -94,75 +105,36 @@ def send_notification(title, message, style=None, img_path=None, channel_id="def
|
|
|
94
105
|
builder.setDefaults(NotificationCompat.DEFAULT_ALL)
|
|
95
106
|
builder.setPriority(NotificationCompat.PRIORITY_HIGH)
|
|
96
107
|
|
|
97
|
-
|
|
98
|
-
img=img_path
|
|
108
|
+
img=None
|
|
99
109
|
if img_path:
|
|
100
110
|
try:
|
|
101
111
|
img = get_image_uri(img_path)
|
|
102
|
-
except
|
|
103
|
-
print('Failed
|
|
104
|
-
|
|
105
|
-
# Add Actions (Buttons)
|
|
106
|
-
|
|
107
|
-
# add Action 1 Button
|
|
108
|
-
# try:
|
|
109
|
-
# # Create Action 1
|
|
110
|
-
# action_intent = Intent(context, PythonActivity)
|
|
111
|
-
# action_intent.setAction("ACTION_ONE")
|
|
112
|
-
# pending_action_intent = PendingIntent.getActivity(
|
|
113
|
-
# context,
|
|
114
|
-
# 0,
|
|
115
|
-
# action_intent,
|
|
116
|
-
# PendingIntent.FLAG_IMMUTABLE
|
|
117
|
-
# )
|
|
118
|
-
|
|
119
|
-
# # Convert text to CharSequence
|
|
120
|
-
# action_text = cast('java.lang.CharSequence', String("Action 1"))
|
|
121
|
-
|
|
122
|
-
# # Add action with proper types
|
|
123
|
-
# builder.addAction(
|
|
124
|
-
# int(context.getApplicationInfo().icon), # Cast icon to int
|
|
125
|
-
# action_text, # CharSequence text
|
|
126
|
-
# pending_action_intent # PendingIntent
|
|
127
|
-
# )
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
# # Set content intent for notification tap
|
|
131
|
-
# builder.setContentIntent(pending_action_intent)
|
|
132
|
-
# except Exception as e:
|
|
133
|
-
# print('Failed adding Action 1',e)
|
|
134
|
-
|
|
112
|
+
except FileNotFoundError as e:
|
|
113
|
+
print('Failed Adding Bitmap: ',e)
|
|
135
114
|
|
|
136
|
-
# Apply styles
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
elif style == "big_picture" and img_path:
|
|
144
|
-
try:
|
|
115
|
+
# Apply notification styles
|
|
116
|
+
try:
|
|
117
|
+
if style == "big_text":
|
|
118
|
+
big_text_style = NotificationCompatBigTextStyle()
|
|
119
|
+
big_text_style.bigText(message)
|
|
120
|
+
builder.setStyle(big_text_style)
|
|
121
|
+
elif style == "big_picture" and img_path:
|
|
145
122
|
bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(img))
|
|
146
|
-
# bitmap = BitmapFactory.decodeFile(img_path)
|
|
147
123
|
builder.setLargeIcon(bitmap)
|
|
148
124
|
big_picture_style = NotificationCompatBigPictureStyle().bigPicture(bitmap)
|
|
149
|
-
# big_picture_style.bigPicture(bitmap).bigLargeIcon(None)
|
|
150
|
-
# big_picture_style.bigLargeIcon(bitmap) # This just changes dropdown app icon
|
|
151
|
-
|
|
152
125
|
builder.setStyle(big_picture_style)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
builder.setStyle(inbox_style)
|
|
160
|
-
elif style == "large_icon" and img_path:
|
|
161
|
-
try:
|
|
126
|
+
elif style == "inbox":
|
|
127
|
+
inbox_style = NotificationCompatInboxStyle()
|
|
128
|
+
for line in message.split("\n"):
|
|
129
|
+
inbox_style.addLine(line)
|
|
130
|
+
builder.setStyle(inbox_style)
|
|
131
|
+
elif style == "large_icon" and img_path:
|
|
162
132
|
bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(img))
|
|
163
133
|
builder.setLargeIcon(bitmap)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
notification_manager.notify(
|
|
134
|
+
except Exception as e:
|
|
135
|
+
print('Failed Adding Style: ',e)
|
|
136
|
+
# Display the notification
|
|
137
|
+
notification_id = random.randint(0, 100)
|
|
138
|
+
notification_manager.notify(notification_id, builder.build())
|
|
139
|
+
return notification_id
|
|
140
|
+
|
android_notify/styles.py
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
class NotificationStyles:
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
class NotificationStyles():
|
|
2
|
+
""" Safely Adding Styles"""
|
|
3
|
+
DEFAULT = "simple"
|
|
4
|
+
|
|
5
|
+
PROGRESS = "progress"
|
|
4
6
|
INBOX = "inbox"
|
|
7
|
+
BIG_TEXT = "big_text"
|
|
8
|
+
|
|
5
9
|
LARGE_ICON = "large_icon"
|
|
10
|
+
BIG_PICTURE = "big_picture"
|
|
11
|
+
BOTH_IMGS = "both_imgs"
|
|
12
|
+
|
|
13
|
+
MESSAGING = "messaging" # TODO
|
|
14
|
+
CUSTOM = "custom" # TODO
|
|
15
|
+
|
android_notify/sword.py
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"""This Module Contain Class for creating Notification With Java"""
|
|
2
|
+
import difflib
|
|
3
|
+
import random
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
from jnius import autoclass,cast # pylint: disable=W0611, C0114
|
|
7
|
+
|
|
8
|
+
DEV=0
|
|
9
|
+
ON_ANDROID = False
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
# Get the required Java classes
|
|
13
|
+
PythonActivity = autoclass('org.kivy.android.PythonActivity')
|
|
14
|
+
String = autoclass('java.lang.String')
|
|
15
|
+
Intent = autoclass('android.content.Intent')
|
|
16
|
+
PendingIntent = autoclass('android.app.PendingIntent')
|
|
17
|
+
context = PythonActivity.mActivity # Get the app's context
|
|
18
|
+
BitmapFactory = autoclass('android.graphics.BitmapFactory')
|
|
19
|
+
BuildVersion = autoclass('android.os.Build$VERSION')
|
|
20
|
+
NotificationManager = autoclass('android.app.NotificationManager')
|
|
21
|
+
NotificationChannel = autoclass('android.app.NotificationChannel')
|
|
22
|
+
ON_ANDROID = True
|
|
23
|
+
except Exception as e:# pylint: disable=W0718
|
|
24
|
+
MESSAGE='This Package Only Runs on Android !!! ---> Check "https://github.com/Fector101/android_notify/" to see design patterns and more info.' # pylint: disable=C0301
|
|
25
|
+
print(MESSAGE if DEV else '')
|
|
26
|
+
|
|
27
|
+
if ON_ANDROID:
|
|
28
|
+
try:
|
|
29
|
+
from android.permissions import request_permissions, Permission,check_permission # pylint: disable=E0401
|
|
30
|
+
from android.storage import app_storage_path # pylint: disable=E0401
|
|
31
|
+
|
|
32
|
+
NotificationManagerCompat = autoclass('androidx.core.app.NotificationManagerCompat')
|
|
33
|
+
NotificationCompat = autoclass('androidx.core.app.NotificationCompat')
|
|
34
|
+
|
|
35
|
+
# Notification Design
|
|
36
|
+
NotificationCompatBuilder = autoclass('androidx.core.app.NotificationCompat$Builder') # pylint: disable=C0301
|
|
37
|
+
NotificationCompatBigTextStyle = autoclass('androidx.core.app.NotificationCompat$BigTextStyle') # pylint: disable=C0301
|
|
38
|
+
NotificationCompatBigPictureStyle = autoclass('androidx.core.app.NotificationCompat$BigPictureStyle') # pylint: disable=C0301
|
|
39
|
+
NotificationCompatInboxStyle = autoclass('androidx.core.app.NotificationCompat$InboxStyle')
|
|
40
|
+
except Exception as e:# pylint: disable=W0718
|
|
41
|
+
print(e if DEV else '','Import Fector101')
|
|
42
|
+
# print(e if DEV else '')
|
|
43
|
+
print("""
|
|
44
|
+
Dependency Error: Add the following in buildozer.spec:
|
|
45
|
+
* android.gradle_dependencies = androidx.core:core-ktx:1.15.0, androidx.core:core:1.6.0
|
|
46
|
+
* android.enable_androidx = True
|
|
47
|
+
* android.permissions = POST_NOTIFICATIONS
|
|
48
|
+
""")
|
|
49
|
+
|
|
50
|
+
class Notification:
|
|
51
|
+
"""
|
|
52
|
+
Send a notification on Android.
|
|
53
|
+
|
|
54
|
+
:param title: Title of the notification.
|
|
55
|
+
:param message: Message body.
|
|
56
|
+
:param style: Style of the notification
|
|
57
|
+
('simple', 'progress', 'big_text', 'inbox', 'big_picture', 'large_icon', 'both_imgs').
|
|
58
|
+
both_imgs == using lager icon and big picture
|
|
59
|
+
:param big_picture_path: Path to the image resource.
|
|
60
|
+
:param large_icon_path: Path to the image resource.
|
|
61
|
+
---
|
|
62
|
+
(Advance Options)
|
|
63
|
+
:param channel_name: Defaults to "Default Channel"
|
|
64
|
+
:param channel_id: Defaults to "default_channel"
|
|
65
|
+
---
|
|
66
|
+
(Options during Dev On PC)
|
|
67
|
+
:param logs: Defaults to True
|
|
68
|
+
"""
|
|
69
|
+
notification_ids=[]
|
|
70
|
+
style_values=[
|
|
71
|
+
'','simple',
|
|
72
|
+
'progress','big_text',
|
|
73
|
+
'inbox', 'big_picture',
|
|
74
|
+
'large_icon','both_imgs',
|
|
75
|
+
'custom'
|
|
76
|
+
] # TODO make pattern for non-android Notifications
|
|
77
|
+
defaults={
|
|
78
|
+
'title':'Default Title',
|
|
79
|
+
'message':'Default Message', # TODO Might change message para to list if style set to inbox
|
|
80
|
+
'style':'simple',
|
|
81
|
+
'big_picture_path':'',
|
|
82
|
+
'large_icon_path':'',
|
|
83
|
+
'progress_max_value': 100,
|
|
84
|
+
'progress_current_value': 0,
|
|
85
|
+
'channel_name':'Default Channel',
|
|
86
|
+
'channel_id':'default_channel',
|
|
87
|
+
'logs':True,
|
|
88
|
+
}
|
|
89
|
+
# During Development (When running on PC)
|
|
90
|
+
logs=not ON_ANDROID
|
|
91
|
+
def __init__(self,**kwargs):
|
|
92
|
+
self.__validateArgs(kwargs)
|
|
93
|
+
# Basic options
|
|
94
|
+
self.title=''
|
|
95
|
+
self.message=''
|
|
96
|
+
self.style=''
|
|
97
|
+
self.large_icon_path=''
|
|
98
|
+
self.big_picture_path=''
|
|
99
|
+
self.progress_current_value=0
|
|
100
|
+
self.progress_max_value=100
|
|
101
|
+
# Advance Options
|
|
102
|
+
self.channel_name=''
|
|
103
|
+
self.channel_id=''
|
|
104
|
+
self.silent=False
|
|
105
|
+
# During Dev on PC
|
|
106
|
+
self.logs=self.logs
|
|
107
|
+
# Private (Don't Touch)
|
|
108
|
+
self.__id = self.__getUniqueID()
|
|
109
|
+
self.__setArgs(kwargs)
|
|
110
|
+
self.__builder=None
|
|
111
|
+
if not ON_ANDROID:
|
|
112
|
+
return
|
|
113
|
+
# TODO make send method wait for __asks_permission_if_needed method
|
|
114
|
+
self.__asks_permission_if_needed()
|
|
115
|
+
self.notification_manager = context.getSystemService(context.NOTIFICATION_SERVICE)
|
|
116
|
+
|
|
117
|
+
def updateTitle(self,new_title):
|
|
118
|
+
"""Changes Old Title
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
new_title (str): New Notification Title
|
|
122
|
+
"""
|
|
123
|
+
self.title=new_title
|
|
124
|
+
if ON_ANDROID:
|
|
125
|
+
self.__builder.setContentTitle(new_title)
|
|
126
|
+
|
|
127
|
+
def updateMessage(self,new_message):
|
|
128
|
+
"""Changes Old Message
|
|
129
|
+
|
|
130
|
+
Args:
|
|
131
|
+
new_message (str): New Notification Message
|
|
132
|
+
"""
|
|
133
|
+
self.message=new_message
|
|
134
|
+
if ON_ANDROID:
|
|
135
|
+
self.__builder.setContentText(new_message)
|
|
136
|
+
|
|
137
|
+
def updateProgressBar(self,current_value,message:str=''):
|
|
138
|
+
"""message defaults to last message"""
|
|
139
|
+
self.__builder.setProgress(self.progress_max_value, current_value, False)
|
|
140
|
+
if message:
|
|
141
|
+
self.__builder.setContentText(String(message))
|
|
142
|
+
self.notification_manager.notify(self.__id, self.__builder.build())
|
|
143
|
+
|
|
144
|
+
def removeProgressBar(self,message=''):
|
|
145
|
+
"""message defaults to last message"""
|
|
146
|
+
if message:
|
|
147
|
+
self.__builder.setContentText(String(message))
|
|
148
|
+
self.__builder.setProgress(0, 0, False)
|
|
149
|
+
self.notification_manager.notify(self.__id, self.__builder.build())
|
|
150
|
+
|
|
151
|
+
def send(self,silent:bool=False):
|
|
152
|
+
"""Sends notification
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
silent (bool): True if you don't want to show briefly on screen
|
|
156
|
+
"""
|
|
157
|
+
self.silent=self.silent or silent
|
|
158
|
+
if ON_ANDROID:
|
|
159
|
+
self.__startNotificationBuild()
|
|
160
|
+
self.notification_manager.notify(self.__id, self.__builder.build())
|
|
161
|
+
elif self.logs:
|
|
162
|
+
print(f"""
|
|
163
|
+
Dev Notification Properties:
|
|
164
|
+
title: '{self.title}'
|
|
165
|
+
message: '{self.message}'
|
|
166
|
+
large_icon_path: '{self.large_icon_path}'
|
|
167
|
+
big_picture_path: '{self.big_picture_path}'
|
|
168
|
+
style: '{self.style}'
|
|
169
|
+
Silent: '{self.silent}'
|
|
170
|
+
(Won't Print Logs When Complied,except if selected `Notification.logs=True`
|
|
171
|
+
""")
|
|
172
|
+
if DEV:
|
|
173
|
+
print(f'channel_name: {self.channel_name}, Channel ID: {self.channel_id}, id: {self.__id}')
|
|
174
|
+
print('Can\'t Send Package Only Runs on Android !!! ---> Check "https://github.com/Fector101/android_notify/" for Documentation.\n' if DEV else '\n') # pylint: disable=C0301
|
|
175
|
+
|
|
176
|
+
def __validateArgs(self,inputted_kwargs):
|
|
177
|
+
|
|
178
|
+
def checkInReference(inputted_keywords,accepteable_inputs,input_type):
|
|
179
|
+
def singularForm(plural_form):
|
|
180
|
+
return plural_form[:-1]
|
|
181
|
+
invalid_args= set(inputted_keywords) - set(accepteable_inputs)
|
|
182
|
+
if invalid_args:
|
|
183
|
+
suggestions=[]
|
|
184
|
+
for arg in invalid_args:
|
|
185
|
+
closest_match = difflib.get_close_matches(arg,accepteable_inputs,n=2,cutoff=0.6)
|
|
186
|
+
if closest_match:
|
|
187
|
+
suggestions.append(f"* '{arg}' Invalid -> Did you mean '{closest_match[0]}'? ") # pylint: disable=C0301
|
|
188
|
+
else:
|
|
189
|
+
suggestions.append(f"* {arg} is not a valid {singularForm(input_type)}.")
|
|
190
|
+
suggestion_text='\n'.join(suggestions)
|
|
191
|
+
hint_msg=singularForm(input_type) if len(invalid_args) < 2 else input_type
|
|
192
|
+
|
|
193
|
+
raise ValueError(f"Invalid {hint_msg} provided: \n\t{suggestion_text}\n\t* list of valid {input_type}: [{', '.join(accepteable_inputs)}]")
|
|
194
|
+
|
|
195
|
+
allowed_keywords=self.defaults.keys()
|
|
196
|
+
inputted_keywords_=inputted_kwargs.keys()
|
|
197
|
+
checkInReference(inputted_keywords_,allowed_keywords,'arguments')
|
|
198
|
+
|
|
199
|
+
# Validate style values
|
|
200
|
+
if 'style' in inputted_keywords_ and inputted_kwargs['style'] not in self.style_values:
|
|
201
|
+
checkInReference([inputted_kwargs['style']],self.style_values,'values')
|
|
202
|
+
|
|
203
|
+
def __setArgs(self,options_dict:dict):
|
|
204
|
+
for key,value in options_dict.items():
|
|
205
|
+
if key == 'channel_name':
|
|
206
|
+
setattr(self,key, value[:40] if value else self.defaults[key])
|
|
207
|
+
elif key == 'channel_id' and value:
|
|
208
|
+
setattr(self,key, self.__generate_channel_id(value) if value else self.defaults[key])
|
|
209
|
+
|
|
210
|
+
setattr(self,key, value if value else self.defaults[key])
|
|
211
|
+
|
|
212
|
+
if "channel_id" not in options_dict and 'channel_name' in options_dict:
|
|
213
|
+
setattr(self,'channel_id', self.__generate_channel_id(options_dict['channel_name']))
|
|
214
|
+
|
|
215
|
+
def __startNotificationBuild(self):
|
|
216
|
+
self.__createBasicNotification()
|
|
217
|
+
if self.style not in ['simple','']:
|
|
218
|
+
self.__addNotificationStyle()
|
|
219
|
+
|
|
220
|
+
def __createBasicNotification(self):
|
|
221
|
+
# Notification Channel (Required for Android 8.0+)
|
|
222
|
+
if BuildVersion.SDK_INT >= 26 and self.notification_manager.getNotificationChannel(self.channel_id) is None:
|
|
223
|
+
importance=NotificationManagerCompat.IMPORTANCE_DEFAULT if self.silent else NotificationManagerCompat.IMPORTANCE_HIGH # pylint: disable=possibly-used-before-assignment
|
|
224
|
+
channel = NotificationChannel(
|
|
225
|
+
self.channel_id,
|
|
226
|
+
self.channel_name,
|
|
227
|
+
importance
|
|
228
|
+
)
|
|
229
|
+
self.notification_manager.createNotificationChannel(channel)
|
|
230
|
+
|
|
231
|
+
# Build the notification
|
|
232
|
+
self.__builder = NotificationCompatBuilder(context, self.channel_id)# pylint: disable=E0606
|
|
233
|
+
self.__builder.setContentTitle(self.title)
|
|
234
|
+
self.__builder.setContentText(self.message)
|
|
235
|
+
self.__builder.setSmallIcon(context.getApplicationInfo().icon)
|
|
236
|
+
self.__builder.setDefaults(NotificationCompat.DEFAULT_ALL) # pylint: disable=E0606
|
|
237
|
+
if not self.silent:
|
|
238
|
+
self.__builder.setPriority(NotificationCompat.PRIORITY_DEFAULT if self.silent else NotificationCompat.PRIORITY_HIGH)
|
|
239
|
+
|
|
240
|
+
def __addNotificationStyle(self):
|
|
241
|
+
# pylint: disable=trailing-whitespace
|
|
242
|
+
|
|
243
|
+
large_icon_javapath=None
|
|
244
|
+
if self.large_icon_path:
|
|
245
|
+
try:
|
|
246
|
+
large_icon_javapath = self.__get_image_uri(self.large_icon_path)
|
|
247
|
+
except FileNotFoundError as e:
|
|
248
|
+
print('Failed Adding Big Picture Bitmap: ',e)
|
|
249
|
+
|
|
250
|
+
big_pic_javapath=None
|
|
251
|
+
if self.big_picture_path:
|
|
252
|
+
try:
|
|
253
|
+
big_pic_javapath = self.__get_image_uri(self.big_picture_path)
|
|
254
|
+
except FileNotFoundError as e:
|
|
255
|
+
print('Failed Adding Lagre Icon Bitmap: ',e)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
if self.style == "big_text":
|
|
259
|
+
big_text_style = NotificationCompatBigTextStyle() # pylint: disable=E0606
|
|
260
|
+
big_text_style.bigText(self.message)
|
|
261
|
+
self.__builder.setStyle(big_text_style)
|
|
262
|
+
|
|
263
|
+
elif self.style == "inbox":
|
|
264
|
+
inbox_style = NotificationCompatInboxStyle() # pylint: disable=E0606
|
|
265
|
+
for line in self.message.split("\n"):
|
|
266
|
+
inbox_style.addLine(line)
|
|
267
|
+
self.__builder.setStyle(inbox_style)
|
|
268
|
+
|
|
269
|
+
elif self.style == "big_picture" and big_pic_javapath:
|
|
270
|
+
big_pic_bitmap = self.__getBitmap(big_pic_javapath)
|
|
271
|
+
big_picture_style = NotificationCompatBigPictureStyle().bigPicture(big_pic_bitmap) # pylint: disable=E0606
|
|
272
|
+
self.__builder.setStyle(big_picture_style)
|
|
273
|
+
|
|
274
|
+
elif self.style == "large_icon" and large_icon_javapath:
|
|
275
|
+
large_icon_bitmap = self.__getBitmap(large_icon_javapath)
|
|
276
|
+
self.__builder.setLargeIcon(large_icon_bitmap)
|
|
277
|
+
|
|
278
|
+
elif self.style == 'both_imgs' and (large_icon_javapath or big_pic_javapath):
|
|
279
|
+
if big_pic_javapath:
|
|
280
|
+
big_pic_bitmap = self.__getBitmap(big_pic_javapath)
|
|
281
|
+
big_picture_style = NotificationCompatBigPictureStyle().bigPicture(big_pic_bitmap)
|
|
282
|
+
self.__builder.setStyle(big_picture_style)
|
|
283
|
+
elif large_icon_javapath:
|
|
284
|
+
large_icon_bitmap = self.__getBitmap(large_icon_javapath)
|
|
285
|
+
self.__builder.setLargeIcon(large_icon_bitmap)
|
|
286
|
+
elif self.style == 'progress':
|
|
287
|
+
self.__builder.setContentTitle(String(self.title))
|
|
288
|
+
self.__builder.setContentText(String(self.message))
|
|
289
|
+
self.__builder.setProgress(self.progress_max_value, self.progress_current_value, False)
|
|
290
|
+
# elif self.style == 'custom':
|
|
291
|
+
# self.__builder = self.__doCustomStyle()
|
|
292
|
+
|
|
293
|
+
# def __doCustomStyle(self):
|
|
294
|
+
# # TODO Will implement when needed
|
|
295
|
+
# return self.__builder
|
|
296
|
+
|
|
297
|
+
def __getUniqueID(self):
|
|
298
|
+
reasonable_amount_of_notifications=101
|
|
299
|
+
notification_id = random.randint(1, reasonable_amount_of_notifications)
|
|
300
|
+
while notification_id in self.notification_ids:
|
|
301
|
+
notification_id = random.randint(1, 100)
|
|
302
|
+
self.notification_ids.append(notification_id)
|
|
303
|
+
return notification_id
|
|
304
|
+
|
|
305
|
+
def __asks_permission_if_needed(self):
|
|
306
|
+
"""
|
|
307
|
+
Ask for permission to send notifications if needed.
|
|
308
|
+
"""
|
|
309
|
+
def on_permissions_result(permissions, grant): # pylint: disable=unused-argument
|
|
310
|
+
if self.logs:
|
|
311
|
+
print("Permission Grant State: ",grant)
|
|
312
|
+
|
|
313
|
+
permissions=[Permission.POST_NOTIFICATIONS] # pylint: disable=E0606
|
|
314
|
+
if not all(check_permission(p) for p in permissions):
|
|
315
|
+
request_permissions(permissions,on_permissions_result) # pylint: disable=E0606
|
|
316
|
+
|
|
317
|
+
def __get_image_uri(self,relative_path):
|
|
318
|
+
"""
|
|
319
|
+
Get the absolute URI for an image in the assets folder.
|
|
320
|
+
:param relative_path: The relative path to the image (e.g., 'assets/imgs/icon.png').
|
|
321
|
+
:return: Absolute URI java Object (e.g., 'file:///path/to/file.png').
|
|
322
|
+
"""
|
|
323
|
+
|
|
324
|
+
output_path = os.path.join(app_storage_path(),'app', relative_path) # pylint: disable=possibly-used-before-assignment
|
|
325
|
+
# print(output_path) # /data/user/0/(package.domain+package.name)/files/app/assets/imgs/icon.png | pylint: disable=:line-too-long
|
|
326
|
+
|
|
327
|
+
if not os.path.exists(output_path):
|
|
328
|
+
# TODO Use images From Any where even Web
|
|
329
|
+
raise FileNotFoundError(f"Image not found at path: {output_path}, (Can Only Use Images in App Path)")
|
|
330
|
+
Uri = autoclass('android.net.Uri')
|
|
331
|
+
return Uri.parse(f"file://{output_path}")
|
|
332
|
+
def __getBitmap(self,img_path):
|
|
333
|
+
return BitmapFactory.decodeStream(context.getContentResolver().openInputStream(img_path))
|
|
334
|
+
|
|
335
|
+
def __generate_channel_id(self,channel_name: str) -> str:
|
|
336
|
+
"""
|
|
337
|
+
Generate a readable and consistent channel ID from a channel name.
|
|
338
|
+
|
|
339
|
+
Args:
|
|
340
|
+
channel_name (str): The name of the notification channel.
|
|
341
|
+
|
|
342
|
+
Returns:
|
|
343
|
+
str: A sanitized channel ID.
|
|
344
|
+
"""
|
|
345
|
+
# Normalize the channel name
|
|
346
|
+
channel_id = channel_name.strip().lower()
|
|
347
|
+
# Replace spaces and special characters with underscores
|
|
348
|
+
channel_id = re.sub(r'[^a-z0-9]+', '_', channel_id)
|
|
349
|
+
# Remove leading/trailing underscores
|
|
350
|
+
channel_id = channel_id.strip('_')
|
|
351
|
+
return channel_id[:50]
|
|
352
|
+
|
|
353
|
+
# try:
|
|
354
|
+
# notify=Notification(titl='My Title',channel_name='Go')#,logs=False)
|
|
355
|
+
# # notify.channel_name='Downloads'
|
|
356
|
+
# notify.message="Blah"
|
|
357
|
+
# notify.send()
|
|
358
|
+
# notify.updateTitle('New Title')
|
|
359
|
+
# notify.updateMessage('New Message')
|
|
360
|
+
# notify.send(True)
|
|
361
|
+
# except Exception as e:
|
|
362
|
+
# print(e)
|
|
363
|
+
|
|
364
|
+
# notify=Notification(title='My Title1')
|
|
365
|
+
# # notify.updateTitle('New Title1')
|
|
366
|
+
# notify.send()
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
# Notification.logs=False # Add in Readme
|
|
370
|
+
# notify=Notification(style='large_icon',title='My Title',channel_name='Some thing about a thing ')#,logs=False)
|
|
371
|
+
# # notify.channel_name='Downloads'
|
|
372
|
+
# notify.message="Blah"
|
|
373
|
+
# notify.send()
|
|
374
|
+
# notify.updateTitle('New Title')
|
|
375
|
+
# notify.updateMessage('New Message')
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: android-notify
|
|
3
|
+
Version: 1.3
|
|
4
|
+
Summary: A Python package that simpilfies creating Android Post notifications using PyJNIus in Kivy apps.
|
|
5
|
+
Home-page: https://github.com/fector101/android-notify
|
|
6
|
+
Author: Fabian
|
|
7
|
+
Author-email: fector101@yahoo.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Documentation, https://github.com/fector101/android-notify/
|
|
10
|
+
Project-URL: Source, https://github.com/fector101/android-notify
|
|
11
|
+
Project-URL: Tracker, https://github.com/fector101/android-notify/issues
|
|
12
|
+
Project-URL: Funding, https://www.buymeacoffee.com/fector101
|
|
13
|
+
Keywords: android,notifications,kivy,mobile,post-notifications,pyjnius,android-notifications,kivy-notifications,python-android,mobile-development,push-notifications,mobile-app,kivy-application
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: Android
|
|
17
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
18
|
+
Classifier: Intended Audience :: Developers
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.6
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
Requires-Dist: kivy>=2.0.0
|
|
23
|
+
Requires-Dist: pyjnius>=1.4.2
|
|
24
|
+
|
|
25
|
+
# Android-Notifiy
|
|
26
|
+
|
|
27
|
+
A Python library for effortlessly creating and managing Android notifications in Kivy android apps.
|
|
28
|
+
Supports various styles and ensures seamless integration and customization.
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- Compatible with Android 8.0+.
|
|
33
|
+
- Supports including images in notifications.
|
|
34
|
+
- Support for multiple notification styles:
|
|
35
|
+
- Progress
|
|
36
|
+
- Big Picture
|
|
37
|
+
- Inbox
|
|
38
|
+
- Big Text
|
|
39
|
+
- Large Icon
|
|
40
|
+
|
|
41
|
+
This module automatically handles:
|
|
42
|
+
|
|
43
|
+
- Permission requests for notifications
|
|
44
|
+
- Customizable notification channels.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
This package is available on PyPI and can be installed via pip:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install android-notify
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## **Dependencies**
|
|
55
|
+
|
|
56
|
+
**Prerequisites:**
|
|
57
|
+
|
|
58
|
+
- Kivy
|
|
59
|
+
|
|
60
|
+
In your **`buildozer.spec`** file, ensure you include the following:
|
|
61
|
+
|
|
62
|
+
```ini
|
|
63
|
+
# Add pyjnius so it's packaged with the build
|
|
64
|
+
requirements = python3, kivy, pyjnius, android-notify
|
|
65
|
+
|
|
66
|
+
# Add permission for notifications
|
|
67
|
+
android.permissions = POST_NOTIFICATIONS
|
|
68
|
+
|
|
69
|
+
# Required dependencies (write exactly as shown, no quotation marks)
|
|
70
|
+
android.gradle_dependencies = androidx.core:core:1.6.0, androidx.core:core-ktx:1.15.0
|
|
71
|
+
android.enable_androidx = True
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Basic Usage
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from android_notify import Notification
|
|
80
|
+
|
|
81
|
+
# Create a simple notification
|
|
82
|
+
notification = Notification(
|
|
83
|
+
title="Hello",
|
|
84
|
+
message="This is a basic notification"
|
|
85
|
+
)
|
|
86
|
+
notification.send()
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Sample Image:**
|
|
90
|
+

|
|
91
|
+
|
|
92
|
+
## Notification Styles
|
|
93
|
+
|
|
94
|
+
The library supports multiple notification styles:
|
|
95
|
+
|
|
96
|
+
1. `simple` - Basic notification with title and message
|
|
97
|
+
2. `progress` - Shows a progress bar
|
|
98
|
+
3. `big_text` - Expandable notification with long text
|
|
99
|
+
4. `inbox` - List-style notification
|
|
100
|
+
5. `big_picture` - Notification with a large image
|
|
101
|
+
6. `large_icon` - Notification with a custom icon
|
|
102
|
+
7. `both_imgs` - Combines big picture and large icon
|
|
103
|
+
8. `custom` - For custom notification styles
|
|
104
|
+
|
|
105
|
+
### Style Examples
|
|
106
|
+
|
|
107
|
+
#### Notification with an Image (Big Picture Style)
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
# Image notification
|
|
111
|
+
notification = Notification(
|
|
112
|
+
title='Picture Alert!',
|
|
113
|
+
message='This notification includes an image.',
|
|
114
|
+
style="big_picture",
|
|
115
|
+
big_picture_path="assets/imgs/photo.png"
|
|
116
|
+
)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Sample Image:**
|
|
120
|
+

|
|
121
|
+
|
|
122
|
+
#### Inbox Notification Style
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
# Send a notification with inbox style
|
|
126
|
+
notification = Notification(
|
|
127
|
+
title='Inbox Notification',
|
|
128
|
+
message='Line 1\nLine 2\nLine 3',
|
|
129
|
+
style='inbox'
|
|
130
|
+
)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Sample Image:**
|
|
134
|
+

|
|
135
|
+
|
|
136
|
+
#### Big text notification (Will Display as simple text if Device dosen't support)
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
notification = Notification(
|
|
140
|
+
title="Article",
|
|
141
|
+
message="Long article content...",
|
|
142
|
+
style="big_text"
|
|
143
|
+
)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
#### Progress bar notification
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
notification = Notification(
|
|
150
|
+
title="Download",
|
|
151
|
+
message="Downloading file...",
|
|
152
|
+
style="progress",
|
|
153
|
+
progress_max_value=100,
|
|
154
|
+
progress_current_value=0
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Sample Image:**
|
|
160
|
+

|
|
161
|
+
|
|
162
|
+
#### Notification with an Image (Large Icon Style)
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
notification = Notification(
|
|
166
|
+
title="Completed download",
|
|
167
|
+
message="profile.jpg",
|
|
168
|
+
style="large_icon",
|
|
169
|
+
large_icon_path="assets/imgs/profile.png"
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Sample Image:**
|
|
175
|
+

|
|
176
|
+
|
|
177
|
+
## Advanced Features
|
|
178
|
+
|
|
179
|
+
### Updating Notifications
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
notification = Notification(title="Initial Title")
|
|
183
|
+
notification.send()
|
|
184
|
+
|
|
185
|
+
# Update title
|
|
186
|
+
notification.updateTitle("New Title")
|
|
187
|
+
|
|
188
|
+
# Update message
|
|
189
|
+
notification.updateMessage("New Message")
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Progress Bar Management
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
notification = Notification(
|
|
196
|
+
title="Download Progress",
|
|
197
|
+
style="progress"
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
# Update progress
|
|
201
|
+
notification.updateProgressBar(50, "50% Complete")
|
|
202
|
+
|
|
203
|
+
# Remove progress bar
|
|
204
|
+
notification.removeProgressBar("Download Complete")
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Channel Management
|
|
208
|
+
|
|
209
|
+
Notifications are organized into channels. You can customize the channel name and ID:
|
|
210
|
+
|
|
211
|
+
- Custom Channel Name's Gives User ability to turn on/off specific
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
notification = Notification(
|
|
215
|
+
title="Download finished",
|
|
216
|
+
message="How to Catch a Fish.mp4",
|
|
217
|
+
channel_name="Download Notifications", # Will create User-visible name "downloads"
|
|
218
|
+
channel_id="custom_downloads" # Optional: specify custom channel ID
|
|
219
|
+
)
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Sample Image:**
|
|
223
|
+

|
|
224
|
+
|
|
225
|
+
### Silent Notifications
|
|
226
|
+
|
|
227
|
+
To send a notification without sound or heads-up display:
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
notification = Notification(title="Silent Update")
|
|
231
|
+
notification.send(silent=True)
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Assist
|
|
235
|
+
|
|
236
|
+
- How to Copy image to app folder
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
import shutil,os # These modules come packaged with python
|
|
240
|
+
from android.storage import app_storage_path # type: ignore -- This works only on android
|
|
241
|
+
|
|
242
|
+
app_path = os.path.join(app_storage_path(),'app')
|
|
243
|
+
image_path= "/storage/emulated/0/Download/profile.png"
|
|
244
|
+
|
|
245
|
+
shutil.copy(image_path, os.path.join(app_path, "profile.png"))
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
- Avoiding Human Error when using different notification styles
|
|
249
|
+
|
|
250
|
+
```python
|
|
251
|
+
from android_notify import Notification, NotificationStyles
|
|
252
|
+
notification = Notification(
|
|
253
|
+
title="New Photo",
|
|
254
|
+
message="Check out this image",
|
|
255
|
+
style=NotificationStyles.BIG_PICTURE,
|
|
256
|
+
big_picture_path="assets/imgs/photo.png"
|
|
257
|
+
).send()
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Development Mode
|
|
261
|
+
|
|
262
|
+
When developing on non-Android platforms, the library provides debugging output:
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
# Enable logs (default is True when not on Android)
|
|
266
|
+
Notification.logs = True
|
|
267
|
+
|
|
268
|
+
# Create notification for testing
|
|
269
|
+
notification = Notification(title="Test")
|
|
270
|
+
notification.send()
|
|
271
|
+
# Will print notification properties instead of sending
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Image Requirements
|
|
275
|
+
|
|
276
|
+
- Images must be located within your app's asset folder
|
|
277
|
+
- Supported paths are relative to your app's storage path
|
|
278
|
+
- Example: `assets/imgs/icon.png`
|
|
279
|
+
|
|
280
|
+
## Error Handling
|
|
281
|
+
|
|
282
|
+
The library validates arguments and provides helpful error messages:
|
|
283
|
+
|
|
284
|
+
- Invalid style names will suggest the closest matching style
|
|
285
|
+
- Invalid arguments will list all valid options
|
|
286
|
+
- Missing image files will raise FileNotFoundError with the attempted path
|
|
287
|
+
|
|
288
|
+
## Limitations
|
|
289
|
+
|
|
290
|
+
1. Only works on Android devices
|
|
291
|
+
2. Images must be within the app's storage path
|
|
292
|
+
3. Channel names are limited to 40 characters
|
|
293
|
+
4. Channel IDs are limited to 50 characters
|
|
294
|
+
|
|
295
|
+
## Best Practices
|
|
296
|
+
|
|
297
|
+
1. Always handle permissions appropriately
|
|
298
|
+
2. Use meaningful channel names for organization
|
|
299
|
+
3. Keep progress bar updates reasonable (don't update too frequently)
|
|
300
|
+
4. Test notifications on different Android versions
|
|
301
|
+
5. Consider using silent notifications for frequent updates
|
|
302
|
+
|
|
303
|
+
## Debugging Tips
|
|
304
|
+
|
|
305
|
+
1. Enable logs during development: `Notification.logs = True`
|
|
306
|
+
2. Check channel creation with Android's notification settings
|
|
307
|
+
3. Verify image paths before sending notifications
|
|
308
|
+
4. Test different styles to ensure proper display
|
|
309
|
+
|
|
310
|
+
Remember to check Android's notification documentation for best practices and guidelines regarding notification frequency and content.
|
|
311
|
+
|
|
312
|
+
## Contribution
|
|
313
|
+
|
|
314
|
+
Feel free to open issues or submit pull requests for improvements!
|
|
315
|
+
|
|
316
|
+
## Reporting Issues
|
|
317
|
+
|
|
318
|
+
Found a bug? Please open an issue on our [GitHub Issues](https://github.com/Fector101/android_notify/issues) page.
|
|
319
|
+
|
|
320
|
+
## Author
|
|
321
|
+
|
|
322
|
+
- Fabian - <fector101@yahoo.com>
|
|
323
|
+
- GitHub: [Android Notify Repo](https://github.com/Fector101/android_notify)
|
|
324
|
+
- Twitter: [FabianDev_](https://twitter.com/intent/user?user_id=1246911115319263233)
|
|
325
|
+
|
|
326
|
+
For feedback or contributions, feel free to reach out!
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## ☕ Support the Project
|
|
331
|
+
|
|
332
|
+
If you find this project helpful, consider buying me a coffee! 😊 Or Giving it a star on 🌟 [GitHub](https://github.com/Fector101/android_notify/) Your support helps maintain and improve the project.
|
|
333
|
+
|
|
334
|
+
<a href="https://www.buymeacoffee.com/fector101" target="_blank">
|
|
335
|
+
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" height="60">
|
|
336
|
+
</a>
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## Acknowledgments
|
|
341
|
+
|
|
342
|
+
- This Project was thoroughly Tested by the [Laner Project](https://github.com/Fector101/Laner/) - A application for Securely Transfering Files Wirelessly between your PC and Phone.
|
|
343
|
+
- Thanks to the Kivy and Pyjnius communities.
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## 🌐 **Links**
|
|
348
|
+
|
|
349
|
+
- **PyPI:** [android-notify on PyPI](https://pypi.org/project/android-notify/)
|
|
350
|
+
- **GitHub:** [Source Code Repository](https://github.com/Fector101/android_notify/)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
android_notify/__init__.py,sha256=dAcsj7M_KHBOira9AVk4LtFFXRHTYsn6tza4Oz7T1MM,107
|
|
2
|
+
android_notify/__main__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
android_notify/core.py,sha256=hHzBnVw25x_WpMHp_HPKCuHEL2mQ7IHC_I3EqQZylas,6081
|
|
4
|
+
android_notify/styles.py,sha256=I2p31qStg9DaML9U4nXRvdpGzpppK6RS-qlDKuOv_Tk,328
|
|
5
|
+
android_notify/sword.py,sha256=8v28Q9x3CRRa3xDbHUd8629S5KvLy7xnjSygbqT-coQ,16271
|
|
6
|
+
android_notify-1.3.dist-info/METADATA,sha256=fA2YdjiuZKnEWirQdnzci1l4di-EXmphkdlp41I0FzU,9831
|
|
7
|
+
android_notify-1.3.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
8
|
+
android_notify-1.3.dist-info/top_level.txt,sha256=IR1ONMrRSRINZpWn2X0dL5gbWwWINsK7PW8Jy2p4fU8,15
|
|
9
|
+
android_notify-1.3.dist-info/RECORD,,
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: android-notify
|
|
3
|
-
Version: 1.1
|
|
4
|
-
Summary: A Python package for sending Android notifications.
|
|
5
|
-
Home-page: https://github.com/Fector101/android_notify/
|
|
6
|
-
Author: Fabian
|
|
7
|
-
Author-email: fabianjoseph063@gmail.com
|
|
8
|
-
Project-URL: Funding, https://buymeacoffee.com/fector101
|
|
9
|
-
Project-URL: Source, https://github.com/Fector101/android_notify/
|
|
10
|
-
Requires-Python: >=3.6
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
Requires-Dist: pyjnius
|
|
13
|
-
|
|
14
|
-
# Android Notify
|
|
15
|
-
|
|
16
|
-
`android_notify` is a Python module designed to simplify sending Android notifications using Kivy and Pyjnius. It supports multiple notification styles, including text, images, and inbox layouts.
|
|
17
|
-
|
|
18
|
-
## Features
|
|
19
|
-
|
|
20
|
-
- Send Android notifications with custom titles and messages.
|
|
21
|
-
- Support for multiple notification styles:
|
|
22
|
-
- Big Text
|
|
23
|
-
- Big Picture
|
|
24
|
-
- Inbox
|
|
25
|
-
- Ability to include images in notifications.
|
|
26
|
-
- Compatible with Android 8.0+ (Notification Channels).
|
|
27
|
-
- Customizable notification channels.
|
|
28
|
-
- Support for large icons in notifications.
|
|
29
|
-
|
|
30
|
-
## Installation
|
|
31
|
-
|
|
32
|
-
Make sure you have the required dependencies installed:
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
pip install android-notify
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Usage
|
|
39
|
-
|
|
40
|
-
**Prerequisites:**
|
|
41
|
-
|
|
42
|
-
- Buildozer
|
|
43
|
-
- Kivy
|
|
44
|
-
|
|
45
|
-
In your **`buildozer.spec`** file, ensure you include the following:
|
|
46
|
-
|
|
47
|
-
```ini
|
|
48
|
-
# Add pyjnius so it's packaged with the build
|
|
49
|
-
requirements = python3,kivy,pyjnius
|
|
50
|
-
|
|
51
|
-
# Add permission for notifications
|
|
52
|
-
android.permissions = POST_NOTIFICATIONS
|
|
53
|
-
|
|
54
|
-
# Required dependencies (write exactly as shown, no quotation marks)
|
|
55
|
-
android.gradle_dependencies = androidx.core:core:1.6.0
|
|
56
|
-
android.enable_androidx = True
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### Example Notification
|
|
60
|
-
|
|
61
|
-
```python
|
|
62
|
-
from android_notify.core import send_notification
|
|
63
|
-
|
|
64
|
-
# Send a basic notification
|
|
65
|
-
send_notification("Hello", "This is a basic notification.")
|
|
66
|
-
|
|
67
|
-
# Send a notification with an image
|
|
68
|
-
send_notification(
|
|
69
|
-
title='Picture Alert!',
|
|
70
|
-
message='This notification includes an image.',
|
|
71
|
-
style='big_picture',
|
|
72
|
-
img_path='assets/imgs/icon.png'
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
# Send a notification with inbox style
|
|
76
|
-
send_notification(
|
|
77
|
-
title='Inbox Notification',
|
|
78
|
-
message='Line 1\nLine 2\nLine 3',
|
|
79
|
-
style='inbox'
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
# Send a Big Text notification (Note this send as a normal notification if not supported on said device)
|
|
83
|
-
send_notification(
|
|
84
|
-
title='Hello!',
|
|
85
|
-
message='This is a sample notification.',
|
|
86
|
-
style='big_text'
|
|
87
|
-
)
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### Function Reference
|
|
91
|
-
|
|
92
|
-
#### `send_notification`
|
|
93
|
-
|
|
94
|
-
- **title** (*str*): Notification title.
|
|
95
|
-
- **message** (*str*): Notification message body.
|
|
96
|
-
- **style** (*str*): Notification style (`big_text`, `big_picture`, `inbox`, `large_icon`).
|
|
97
|
-
- **img_path** (*str*): Path to the image (for `big_picture` or `large_icon` styles).
|
|
98
|
-
- **channel_id** (*str*): Notification channel ID.
|
|
99
|
-
|
|
100
|
-
#### `get_image_uri`
|
|
101
|
-
|
|
102
|
-
- Resolves the absolute URI of an image resource.
|
|
103
|
-
- **relative_path** (*str*): The relative path to the image.
|
|
104
|
-
|
|
105
|
-
### Advanced Usage
|
|
106
|
-
|
|
107
|
-
You can customize notification channels for different types of notifications.
|
|
108
|
-
|
|
109
|
-
```python
|
|
110
|
-
send_notification(
|
|
111
|
-
title='Custom Channel Notification',
|
|
112
|
-
message='This uses a custom notification channel.',
|
|
113
|
-
channel_id='custom_channel'
|
|
114
|
-
)
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
## Contribution
|
|
118
|
-
|
|
119
|
-
Feel free to open issues or submit pull requests for improvements!
|
|
120
|
-
|
|
121
|
-
## 🐛 Reporting Issues
|
|
122
|
-
|
|
123
|
-
Found a bug? Please open an issue on our [GitHub Issues](https://github.com/Fector101/android_notify/issues) page.
|
|
124
|
-
|
|
125
|
-
## ☕ Support the Project
|
|
126
|
-
|
|
127
|
-
If you find this project helpful, consider buying me a coffee! Your support helps maintain and improve the project.
|
|
128
|
-
|
|
129
|
-
<a href="https://www.buymeacoffee.com/fector101" target="_blank">
|
|
130
|
-
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" height="60">
|
|
131
|
-
</a>
|
|
132
|
-
|
|
133
|
-
## Author
|
|
134
|
-
|
|
135
|
-
- Fabian - <fector101@yahoo.com>
|
|
136
|
-
- GitHub: <https://github.com/Fector101/android_notify>
|
|
137
|
-
|
|
138
|
-
## Acknowledgments
|
|
139
|
-
|
|
140
|
-
- Thanks to the Kivy and Pyjnius communities for their support.
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
android_notify/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
android_notify/__main__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
android_notify/core.py,sha256=0edRXIF6ltTboJtkGjnOhLJDrYCYa2fzrB7cy61Y1PM,6598
|
|
4
|
-
android_notify/styles.py,sha256=P_8sAqb3Hbf_vbhqSoCVjKeqJ05Fr_CksO-HX5pj8pU,134
|
|
5
|
-
android_notify-1.1.dist-info/METADATA,sha256=q2w4ak4jAcfJ9103bpKU-kPXdFdVgtpc4cbI7z5nd9I,3808
|
|
6
|
-
android_notify-1.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
7
|
-
android_notify-1.1.dist-info/top_level.txt,sha256=IR1ONMrRSRINZpWn2X0dL5gbWwWINsK7PW8Jy2p4fU8,15
|
|
8
|
-
android_notify-1.1.dist-info/RECORD,,
|
|
File without changes
|