android-notify 0.1__tar.gz → 0.2__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 → android_notify-0.2}/PKG-INFO +1 -2
- {android_notify-0.1 → android_notify-0.2}/android_notify/core.py +43 -3
- {android_notify-0.1 → android_notify-0.2}/android_notify.egg-info/PKG-INFO +2 -3
- {android_notify-0.1 → android_notify-0.2}/setup.py +1 -1
- {android_notify-0.1 → android_notify-0.2}/README.md +0 -0
- {android_notify-0.1 → android_notify-0.2}/android_notify/__init__.py +0 -0
- {android_notify-0.1 → android_notify-0.2}/android_notify/__main__.py +0 -0
- {android_notify-0.1 → android_notify-0.2}/android_notify/styles.py +0 -0
- {android_notify-0.1 → android_notify-0.2}/android_notify.egg-info/SOURCES.txt +0 -0
- {android_notify-0.1 → android_notify-0.2}/android_notify.egg-info/dependency_links.txt +0 -0
- {android_notify-0.1 → android_notify-0.2}/android_notify.egg-info/requires.txt +0 -0
- {android_notify-0.1 → android_notify-0.2}/android_notify.egg-info/top_level.txt +0 -0
- {android_notify-0.1 → android_notify-0.2}/setup.cfg +0 -0
|
@@ -1,7 +1,39 @@
|
|
|
1
1
|
from jnius import autoclass
|
|
2
2
|
import random
|
|
3
|
+
from jnius import autoclass
|
|
4
|
+
import os
|
|
5
|
+
import shutil
|
|
6
|
+
|
|
7
|
+
def get_image_uri(relative_path):
|
|
8
|
+
"""
|
|
9
|
+
Get the absolute URI for an image in the assets folder.
|
|
10
|
+
:param relative_path: The relative path to the image (e.g., 'assets/imgs/icon.png').
|
|
11
|
+
:return: Absolute URI (e.g., 'file:///path/to/file.png').
|
|
12
|
+
"""
|
|
13
|
+
# Access Android's context and asset manager
|
|
14
|
+
PythonActivity = autoclass('org.kivy.android.PythonActivity')
|
|
15
|
+
context = PythonActivity.mActivity
|
|
16
|
+
asset_manager = context.getAssets()
|
|
17
|
+
|
|
18
|
+
# Construct the full path for the output file in cache directory
|
|
19
|
+
cache_dir = context.getCacheDir().getAbsolutePath()
|
|
20
|
+
file_name = os.path.basename(relative_path)
|
|
21
|
+
output_path = os.path.join(cache_dir, file_name)
|
|
22
|
+
|
|
23
|
+
# Copy the file from assets to cache directory
|
|
24
|
+
with asset_manager.open(relative_path) as asset_file:
|
|
25
|
+
with open(output_path, 'wb') as output_file:
|
|
26
|
+
shutil.copyfileobj(asset_file, output_file)
|
|
27
|
+
|
|
28
|
+
# Return the URI
|
|
29
|
+
Uri = autoclass('android.net.Uri')
|
|
30
|
+
return Uri.parse(f"file://{output_path}")
|
|
31
|
+
|
|
32
|
+
# # Example usage
|
|
33
|
+
# image_uri = get_image_uri("imgs/icon.png")
|
|
34
|
+
# print(image_uri)
|
|
3
35
|
|
|
4
|
-
def send_notification(title, message, style=None,
|
|
36
|
+
def send_notification(title, message, style=None, img_path=None, channel_id="default_channel"):
|
|
5
37
|
"""
|
|
6
38
|
Send a notification on Android.
|
|
7
39
|
|
|
@@ -40,13 +72,21 @@ def send_notification(title, message, style=None, image=None, channel_id="defaul
|
|
|
40
72
|
builder.setContentText(message)
|
|
41
73
|
builder.setSmallIcon(context.getApplicationInfo().icon)
|
|
42
74
|
|
|
75
|
+
|
|
76
|
+
# Get Image
|
|
77
|
+
if img_path:
|
|
78
|
+
try:
|
|
79
|
+
img_path = get_image_uri(img_path)
|
|
80
|
+
except Exception as e:
|
|
81
|
+
print('Failed getting Image path',e)
|
|
82
|
+
|
|
43
83
|
# Apply styles
|
|
44
84
|
if style == "big_text":
|
|
45
85
|
big_text_style = NotificationCompatBigTextStyle()
|
|
46
86
|
big_text_style.bigText(message)
|
|
47
87
|
builder.setStyle(big_text_style)
|
|
48
|
-
elif style == "big_picture" and
|
|
49
|
-
bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(
|
|
88
|
+
elif style == "big_picture" and img_path:
|
|
89
|
+
bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(img_path))
|
|
50
90
|
big_picture_style = NotificationCompatBigPictureStyle()
|
|
51
91
|
big_picture_style.bigPicture(bitmap)
|
|
52
92
|
builder.setStyle(big_picture_style)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|