android-notify 0.2__py3-none-any.whl → 0.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/core.py CHANGED
@@ -1,38 +1,23 @@
1
- from jnius import autoclass
1
+
2
+ from jnius import autoclass,cast
2
3
  import random
3
- from jnius import autoclass
4
4
  import os
5
- import shutil
6
5
 
7
6
  def get_image_uri(relative_path):
8
7
  """
9
8
  Get the absolute URI for an image in the assets folder.
10
9
  :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').
10
+ :return: Absolute URI java Object (e.g., 'file:///path/to/file.png').
12
11
  """
13
- # Access Android's context and asset manager
14
- PythonActivity = autoclass('org.kivy.android.PythonActivity')
15
- context = PythonActivity.mActivity
16
- asset_manager = context.getAssets()
12
+ from android.storage import app_storage_path # type: ignore
13
+ # print("app_storage_path()",app_storage_path())
17
14
 
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)
15
+ output_path = os.path.join(app_storage_path(),'app', relative_path)
16
+ # print(output_path,'output_path') # /data/user/0/org.laner.lan_ft/files/app/assets/imgs/icon.png
22
17
 
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
18
  Uri = autoclass('android.net.Uri')
30
19
  return Uri.parse(f"file://{output_path}")
31
20
 
32
- # # Example usage
33
- # image_uri = get_image_uri("imgs/icon.png")
34
- # print(image_uri)
35
-
36
21
  def send_notification(title, message, style=None, img_path=None, channel_id="default_channel"):
37
22
  """
38
23
  Send a notification on Android.
@@ -43,26 +28,43 @@ def send_notification(title, message, style=None, img_path=None, channel_id="def
43
28
  :param image: Image URL or drawable for 'big_picture' style.
44
29
  :param channel_id: Notification channel ID.
45
30
  """
31
+ # TODO check if running on android short circuit and return message if not
32
+
46
33
  # Get the required Java classes
34
+ # Notification Base
47
35
  PythonActivity = autoclass('org.kivy.android.PythonActivity')
48
- NotificationManager = autoclass('android.app.NotificationManager')
49
36
  NotificationChannel = autoclass('android.app.NotificationChannel')
37
+ String = autoclass('java.lang.String')
38
+
39
+
40
+ NotificationManagerCompat = autoclass('androidx.core.app.NotificationManagerCompat')
41
+ NotificationCompat = autoclass('androidx.core.app.NotificationCompat')
42
+
43
+ # Notification Design
50
44
  NotificationCompatBuilder = autoclass('androidx.core.app.NotificationCompat$Builder')
51
45
  NotificationCompatBigTextStyle = autoclass('androidx.core.app.NotificationCompat$BigTextStyle')
46
+ # NotificationCompatBigTextStyle = autoclass('android.app.Notification$BigTextStyle')
47
+
52
48
  NotificationCompatBigPictureStyle = autoclass('androidx.core.app.NotificationCompat$BigPictureStyle')
53
49
  NotificationCompatInboxStyle = autoclass('androidx.core.app.NotificationCompat$InboxStyle')
54
50
  BitmapFactory = autoclass('android.graphics.BitmapFactory')
55
-
51
+ BuildVersion = autoclass('android.os.Build$VERSION')
52
+ PendingIntent = autoclass('android.app.PendingIntent')
53
+ Intent = autoclass('android.content.Intent')
54
+
56
55
  # Get the app's context and notification manager
57
56
  context = PythonActivity.mActivity
58
57
  notification_manager = context.getSystemService(context.NOTIFICATION_SERVICE)
59
58
 
59
+ importance= NotificationManagerCompat.IMPORTANCE_HIGH #autoclass('android.app.NotificationManager').IMPORTANCE_HIGH also works #NotificationManager.IMPORTANCE_DEFAULT
60
+
60
61
  # Notification Channel (Required for Android 8.0+)
61
- if notification_manager.getNotificationChannel(channel_id) is None:
62
+ if BuildVersion.SDK_INT >= 26:
63
+ print('entered....')
62
64
  channel = NotificationChannel(
63
65
  channel_id,
64
66
  "Default Channel",
65
- NotificationManager.IMPORTANCE_DEFAULT
67
+ importance
66
68
  )
67
69
  notification_manager.createNotificationChannel(channel)
68
70
 
@@ -71,30 +73,78 @@ def send_notification(title, message, style=None, img_path=None, channel_id="def
71
73
  builder.setContentTitle(title)
72
74
  builder.setContentText(message)
73
75
  builder.setSmallIcon(context.getApplicationInfo().icon)
74
-
76
+ builder.setDefaults(NotificationCompat.DEFAULT_ALL)
77
+ builder.setPriority(NotificationCompat.PRIORITY_HIGH)
75
78
 
76
79
  # Get Image
80
+ img=img_path
77
81
  if img_path:
78
82
  try:
79
- img_path = get_image_uri(img_path)
83
+ img = get_image_uri(img_path)
80
84
  except Exception as e:
81
85
  print('Failed getting Image path',e)
82
86
 
87
+ # Add Actions (Buttons)
88
+
89
+ # add Action 1 Button
90
+ # try:
91
+ # # Create Action 1
92
+ # action_intent = Intent(context, PythonActivity)
93
+ # action_intent.setAction("ACTION_ONE")
94
+ # pending_action_intent = PendingIntent.getActivity(
95
+ # context,
96
+ # 0,
97
+ # action_intent,
98
+ # PendingIntent.FLAG_IMMUTABLE
99
+ # )
100
+
101
+ # # Convert text to CharSequence
102
+ # action_text = cast('java.lang.CharSequence', String("Action 1"))
103
+
104
+ # # Add action with proper types
105
+ # builder.addAction(
106
+ # int(context.getApplicationInfo().icon), # Cast icon to int
107
+ # action_text, # CharSequence text
108
+ # pending_action_intent # PendingIntent
109
+ # )
110
+
111
+
112
+ # # Set content intent for notification tap
113
+ # builder.setContentIntent(pending_action_intent)
114
+ # except Exception as e:
115
+ # print('Failed adding Action 1',e)
116
+
117
+
83
118
  # Apply styles
84
119
  if style == "big_text":
85
120
  big_text_style = NotificationCompatBigTextStyle()
86
121
  big_text_style.bigText(message)
87
122
  builder.setStyle(big_text_style)
123
+
124
+
88
125
  elif style == "big_picture" and img_path:
89
- bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(img_path))
90
- big_picture_style = NotificationCompatBigPictureStyle()
91
- big_picture_style.bigPicture(bitmap)
92
- builder.setStyle(big_picture_style)
126
+ try:
127
+ bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(img))
128
+ # bitmap = BitmapFactory.decodeFile(img_path)
129
+ builder.setLargeIcon(bitmap)
130
+ big_picture_style = NotificationCompatBigPictureStyle().bigPicture(bitmap)
131
+ # big_picture_style.bigPicture(bitmap).bigLargeIcon(None)
132
+ # big_picture_style.bigLargeIcon(bitmap) # This just changes dropdown app icon
133
+
134
+ builder.setStyle(big_picture_style)
135
+ except Exception as e:
136
+ print('Failed Adding Bitmap...', e)
93
137
  elif style == "inbox":
94
138
  inbox_style = NotificationCompatInboxStyle()
95
139
  for line in message.split("\n"):
96
140
  inbox_style.addLine(line)
97
141
  builder.setStyle(inbox_style)
98
-
142
+ elif style == "large_icon" and img_path:
143
+ try:
144
+ bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(img))
145
+ builder.setLargeIcon(bitmap)
146
+ except Exception as e:
147
+ print('Failed Large Icon...', e)
148
+
99
149
  # Show the notification
100
150
  notification_manager.notify(random.randint(0, 100), builder.build())
android_notify/styles.py CHANGED
@@ -2,3 +2,4 @@ class NotificationStyles:
2
2
  BIG_TEXT = "big_text"
3
3
  BIG_PICTURE = "big_picture"
4
4
  INBOX = "inbox"
5
+ LARGE_ICON = "large_icon"
@@ -0,0 +1,116 @@
1
+ Metadata-Version: 2.1
2
+ Name: android-notify
3
+ Version: 0.3
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
+ Requires-Python: >=3.6
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: pyjnius
11
+
12
+ # Android Notify
13
+
14
+ `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.
15
+
16
+ ## Features
17
+
18
+ - Send Android notifications with custom titles and messages.
19
+ - Support for multiple notification styles:
20
+ - Big Text
21
+ - Big Picture
22
+ - Inbox
23
+ - Ability to include images in notifications.
24
+ - Compatible with Android 8.0+ (Notification Channels).
25
+ - Customizable notification channels.
26
+ - Support for large icons in notifications.
27
+
28
+ ## Installation
29
+
30
+ Make sure you have the required dependencies installed:
31
+
32
+ ```bash
33
+ pip install android_notify
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ### Example Notification
39
+
40
+ ```python
41
+ from android_notify.core import send_notification
42
+
43
+ # Send a basic notification
44
+ send_notification(
45
+ title='Hello!',
46
+ message='This is a sample notification.',
47
+ style='big_text'
48
+ )
49
+
50
+ # Send a notification with an image
51
+ send_notification(
52
+ title='Picture Alert!',
53
+ message='This notification includes an image.',
54
+ style='big_picture',
55
+ img_path='assets/imgs/icon.png'
56
+ )
57
+
58
+ # Send a notification with inbox style
59
+ send_notification(
60
+ title='Inbox Notification',
61
+ message='Line 1\nLine 2\nLine 3',
62
+ style='inbox'
63
+ )
64
+ ```
65
+
66
+ ### Function Reference
67
+
68
+ #### `send_notification`
69
+
70
+ - **title** (*str*): Notification title.
71
+ - **message** (*str*): Notification message body.
72
+ - **style** (*str*): Notification style (`big_text`, `big_picture`, `inbox`, `large_icon`).
73
+ - **img_path** (*str*): Path to the image (for `big_picture` or `large_icon` styles).
74
+ - **channel_id** (*str*): Notification channel ID.
75
+
76
+ #### `get_image_uri`
77
+
78
+ - Resolves the absolute URI of an image resource.
79
+ - **relative_path** (*str*): The relative path to the image.
80
+
81
+ ### Advanced Usage
82
+
83
+ You can customize notification channels for different types of notifications.
84
+
85
+ ```python
86
+ send_notification(
87
+ title='Custom Channel Notification',
88
+ message='This uses a custom notification channel.',
89
+ channel_id='custom_channel'
90
+ )
91
+ ```
92
+
93
+ ## Requirements
94
+
95
+ - Python 3.x
96
+ - Kivy
97
+ - Pyjnius
98
+ - Android SDK (For building APKs)
99
+
100
+ ## License
101
+
102
+ This project is licensed under the MIT License.
103
+
104
+ ## Contribution
105
+
106
+ Feel free to open issues or submit pull requests for improvements!
107
+
108
+ ## Author
109
+
110
+ **Fabian** - *Full-Stack Developer* 🚀
111
+
112
+ ## Acknowledgments
113
+
114
+ - Thanks to the Kivy and Pyjnius communities for their support.
115
+ - Inspired by modern Android notification practices.
116
+
@@ -0,0 +1,8 @@
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=_OlwriMgR3qqC_kDZf_fvuOO9_UO0SOkg49n2P2bKfQ,6040
4
+ android_notify/styles.py,sha256=P_8sAqb3Hbf_vbhqSoCVjKeqJ05Fr_CksO-HX5pj8pU,134
5
+ android_notify-0.3.dist-info/METADATA,sha256=9cF2tcS-mrMifHQqdbnD1ywoxiElkcjS8eNaiyKluB8,2761
6
+ android_notify-0.3.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
7
+ android_notify-0.3.dist-info/top_level.txt,sha256=IR1ONMrRSRINZpWn2X0dL5gbWwWINsK7PW8Jy2p4fU8,15
8
+ android_notify-0.3.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: android-notify
3
- Version: 0.2
4
- Summary: A Python package for sending Android notifications.
5
- Requires-Dist: pyjnius
6
-
@@ -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=lzwWcrcBXpDuZC6AQUo26NgHxDW9FFwTcS1DWFH_4Gs,4022
4
- android_notify/styles.py,sha256=OJBh-a2d_iOPcv50n_wUXezmh8Oc9MKDwM7c-RjkLAI,104
5
- android_notify-0.2.dist-info/METADATA,sha256=jPtCK-lTYxk8MjCJ0ipqLa61_S3efI8aRbpoVxST2K4,141
6
- android_notify-0.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
7
- android_notify-0.2.dist-info/top_level.txt,sha256=IR1ONMrRSRINZpWn2X0dL5gbWwWINsK7PW8Jy2p4fU8,15
8
- android_notify-0.2.dist-info/RECORD,,