android-notify 0.1__tar.gz
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-0.1/PKG-INFO +5 -0
- android_notify-0.1/README.md +26 -0
- android_notify-0.1/android_notify/__init__.py +0 -0
- android_notify-0.1/android_notify/__main__.py +0 -0
- android_notify-0.1/android_notify/core.py +60 -0
- android_notify-0.1/android_notify/styles.py +4 -0
- android_notify-0.1/android_notify.egg-info/PKG-INFO +5 -0
- android_notify-0.1/android_notify.egg-info/SOURCES.txt +11 -0
- android_notify-0.1/android_notify.egg-info/dependency_links.txt +1 -0
- android_notify-0.1/android_notify.egg-info/requires.txt +1 -0
- android_notify-0.1/android_notify.egg-info/top_level.txt +1 -0
- android_notify-0.1/setup.cfg +4 -0
- android_notify-0.1/setup.py +9 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Usage
|
|
2
|
+
|
|
3
|
+
```python
|
|
4
|
+
from android_notify.core import send_notification
|
|
5
|
+
from android_notify.styles import NotificationStyles
|
|
6
|
+
|
|
7
|
+
# Send a basic notification
|
|
8
|
+
send_notification("Hello", "This is a basic notification.")
|
|
9
|
+
|
|
10
|
+
# Send a big text notification
|
|
11
|
+
send_notification("Big Text", "This is a notification with a lot of text to show.", style=NotificationStyles.BIG_TEXT)
|
|
12
|
+
|
|
13
|
+
# Send a big picture notification
|
|
14
|
+
from jnius import autoclass
|
|
15
|
+
Uri = autoclass('android.net.Uri')
|
|
16
|
+
image_uri = Uri.parse("file:///path/to/image.jpg")
|
|
17
|
+
send_notification("Big Picture", "Here's a notification with a picture.", style=NotificationStyles.BIG_PICTURE, image=image_uri)
|
|
18
|
+
|
|
19
|
+
# Send an inbox style notification
|
|
20
|
+
send_notification(
|
|
21
|
+
"Inbox Style",
|
|
22
|
+
"Line 1\nLine 2\nLine 3\nLine 4",
|
|
23
|
+
style=NotificationStyles.INBOX
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
```
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from jnius import autoclass
|
|
2
|
+
import random
|
|
3
|
+
|
|
4
|
+
def send_notification(title, message, style=None, image=None, channel_id="default_channel"):
|
|
5
|
+
"""
|
|
6
|
+
Send a notification on Android.
|
|
7
|
+
|
|
8
|
+
:param title: Title of the notification.
|
|
9
|
+
:param message: Message body.
|
|
10
|
+
:param style: Style of the notification ('big_text', 'big_picture', 'inbox').
|
|
11
|
+
:param image: Image URL or drawable for 'big_picture' style.
|
|
12
|
+
:param channel_id: Notification channel ID.
|
|
13
|
+
"""
|
|
14
|
+
# Get the required Java classes
|
|
15
|
+
PythonActivity = autoclass('org.kivy.android.PythonActivity')
|
|
16
|
+
NotificationManager = autoclass('android.app.NotificationManager')
|
|
17
|
+
NotificationChannel = autoclass('android.app.NotificationChannel')
|
|
18
|
+
NotificationCompatBuilder = autoclass('androidx.core.app.NotificationCompat$Builder')
|
|
19
|
+
NotificationCompatBigTextStyle = autoclass('androidx.core.app.NotificationCompat$BigTextStyle')
|
|
20
|
+
NotificationCompatBigPictureStyle = autoclass('androidx.core.app.NotificationCompat$BigPictureStyle')
|
|
21
|
+
NotificationCompatInboxStyle = autoclass('androidx.core.app.NotificationCompat$InboxStyle')
|
|
22
|
+
BitmapFactory = autoclass('android.graphics.BitmapFactory')
|
|
23
|
+
|
|
24
|
+
# Get the app's context and notification manager
|
|
25
|
+
context = PythonActivity.mActivity
|
|
26
|
+
notification_manager = context.getSystemService(context.NOTIFICATION_SERVICE)
|
|
27
|
+
|
|
28
|
+
# Notification Channel (Required for Android 8.0+)
|
|
29
|
+
if notification_manager.getNotificationChannel(channel_id) is None:
|
|
30
|
+
channel = NotificationChannel(
|
|
31
|
+
channel_id,
|
|
32
|
+
"Default Channel",
|
|
33
|
+
NotificationManager.IMPORTANCE_DEFAULT
|
|
34
|
+
)
|
|
35
|
+
notification_manager.createNotificationChannel(channel)
|
|
36
|
+
|
|
37
|
+
# Build the notification
|
|
38
|
+
builder = NotificationCompatBuilder(context, channel_id)
|
|
39
|
+
builder.setContentTitle(title)
|
|
40
|
+
builder.setContentText(message)
|
|
41
|
+
builder.setSmallIcon(context.getApplicationInfo().icon)
|
|
42
|
+
|
|
43
|
+
# Apply styles
|
|
44
|
+
if style == "big_text":
|
|
45
|
+
big_text_style = NotificationCompatBigTextStyle()
|
|
46
|
+
big_text_style.bigText(message)
|
|
47
|
+
builder.setStyle(big_text_style)
|
|
48
|
+
elif style == "big_picture" and image:
|
|
49
|
+
bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(image))
|
|
50
|
+
big_picture_style = NotificationCompatBigPictureStyle()
|
|
51
|
+
big_picture_style.bigPicture(bitmap)
|
|
52
|
+
builder.setStyle(big_picture_style)
|
|
53
|
+
elif style == "inbox":
|
|
54
|
+
inbox_style = NotificationCompatInboxStyle()
|
|
55
|
+
for line in message.split("\n"):
|
|
56
|
+
inbox_style.addLine(line)
|
|
57
|
+
builder.setStyle(inbox_style)
|
|
58
|
+
|
|
59
|
+
# Show the notification
|
|
60
|
+
notification_manager.notify(random.randint(0, 100), builder.build())
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
android_notify/__init__.py
|
|
4
|
+
android_notify/__main__.py
|
|
5
|
+
android_notify/core.py
|
|
6
|
+
android_notify/styles.py
|
|
7
|
+
android_notify.egg-info/PKG-INFO
|
|
8
|
+
android_notify.egg-info/SOURCES.txt
|
|
9
|
+
android_notify.egg-info/dependency_links.txt
|
|
10
|
+
android_notify.egg-info/requires.txt
|
|
11
|
+
android_notify.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pyjnius
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
android_notify
|