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.

@@ -1,5 +1,4 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: android_notify
3
- Version: 0.1
3
+ Version: 0.2
4
4
  Summary: A Python package for sending Android notifications.
5
- Requires-Dist: pyjnius
@@ -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, image=None, channel_id="default_channel"):
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 image:
49
- bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(image))
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)
@@ -1,5 +1,4 @@
1
1
  Metadata-Version: 2.1
2
- Name: android_notify
3
- Version: 0.1
2
+ Name: android-notify
3
+ Version: 0.2
4
4
  Summary: A Python package for sending Android notifications.
5
- Requires-Dist: pyjnius
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='android_notify',
5
- version='0.1',
5
+ version='0.2',
6
6
  description='A Python package for sending Android notifications.',
7
7
  packages=find_packages(),
8
8
  install_requires=['pyjnius'],
File without changes
File without changes