android-notify 0.1__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,7 +1,24 @@
1
- from jnius import autoclass
1
+
2
+ from jnius import autoclass,cast
2
3
  import random
4
+ import os
5
+
6
+ def get_image_uri(relative_path):
7
+ """
8
+ Get the absolute URI for an image in the assets folder.
9
+ :param relative_path: The relative path to the image (e.g., 'assets/imgs/icon.png').
10
+ :return: Absolute URI java Object (e.g., 'file:///path/to/file.png').
11
+ """
12
+ from android.storage import app_storage_path # type: ignore
13
+ # print("app_storage_path()",app_storage_path())
3
14
 
4
- def send_notification(title, message, style=None, image=None, channel_id="default_channel"):
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
17
+
18
+ Uri = autoclass('android.net.Uri')
19
+ return Uri.parse(f"file://{output_path}")
20
+
21
+ def send_notification(title, message, style=None, img_path=None, channel_id="default_channel"):
5
22
  """
6
23
  Send a notification on Android.
7
24
 
@@ -11,26 +28,43 @@ def send_notification(title, message, style=None, image=None, channel_id="defaul
11
28
  :param image: Image URL or drawable for 'big_picture' style.
12
29
  :param channel_id: Notification channel ID.
13
30
  """
31
+ # TODO check if running on android short circuit and return message if not
32
+
14
33
  # Get the required Java classes
34
+ # Notification Base
15
35
  PythonActivity = autoclass('org.kivy.android.PythonActivity')
16
- NotificationManager = autoclass('android.app.NotificationManager')
17
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
18
44
  NotificationCompatBuilder = autoclass('androidx.core.app.NotificationCompat$Builder')
19
45
  NotificationCompatBigTextStyle = autoclass('androidx.core.app.NotificationCompat$BigTextStyle')
46
+ # NotificationCompatBigTextStyle = autoclass('android.app.Notification$BigTextStyle')
47
+
20
48
  NotificationCompatBigPictureStyle = autoclass('androidx.core.app.NotificationCompat$BigPictureStyle')
21
49
  NotificationCompatInboxStyle = autoclass('androidx.core.app.NotificationCompat$InboxStyle')
22
50
  BitmapFactory = autoclass('android.graphics.BitmapFactory')
23
-
51
+ BuildVersion = autoclass('android.os.Build$VERSION')
52
+ PendingIntent = autoclass('android.app.PendingIntent')
53
+ Intent = autoclass('android.content.Intent')
54
+
24
55
  # Get the app's context and notification manager
25
56
  context = PythonActivity.mActivity
26
57
  notification_manager = context.getSystemService(context.NOTIFICATION_SERVICE)
27
58
 
59
+ importance= NotificationManagerCompat.IMPORTANCE_HIGH #autoclass('android.app.NotificationManager').IMPORTANCE_HIGH also works #NotificationManager.IMPORTANCE_DEFAULT
60
+
28
61
  # Notification Channel (Required for Android 8.0+)
29
- if notification_manager.getNotificationChannel(channel_id) is None:
62
+ if BuildVersion.SDK_INT >= 26:
63
+ print('entered....')
30
64
  channel = NotificationChannel(
31
65
  channel_id,
32
66
  "Default Channel",
33
- NotificationManager.IMPORTANCE_DEFAULT
67
+ importance
34
68
  )
35
69
  notification_manager.createNotificationChannel(channel)
36
70
 
@@ -39,22 +73,78 @@ def send_notification(title, message, style=None, image=None, channel_id="defaul
39
73
  builder.setContentTitle(title)
40
74
  builder.setContentText(message)
41
75
  builder.setSmallIcon(context.getApplicationInfo().icon)
76
+ builder.setDefaults(NotificationCompat.DEFAULT_ALL)
77
+ builder.setPriority(NotificationCompat.PRIORITY_HIGH)
78
+
79
+ # Get Image
80
+ img=img_path
81
+ if img_path:
82
+ try:
83
+ img = get_image_uri(img_path)
84
+ except Exception as e:
85
+ print('Failed getting Image path',e)
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)
42
116
 
117
+
43
118
  # Apply styles
44
119
  if style == "big_text":
45
120
  big_text_style = NotificationCompatBigTextStyle()
46
121
  big_text_style.bigText(message)
47
122
  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)
123
+
124
+
125
+ elif style == "big_picture" and img_path:
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)
53
137
  elif style == "inbox":
54
138
  inbox_style = NotificationCompatInboxStyle()
55
139
  for line in message.split("\n"):
56
140
  inbox_style.addLine(line)
57
141
  builder.setStyle(inbox_style)
58
-
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
+
59
149
  # Show the notification
60
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,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: bdist_wheel (0.42.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,5 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: android_notify
3
- Version: 0.1
4
- Summary: A Python package for sending Android notifications.
5
- Requires-Dist: pyjnius
@@ -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=jBIoLL60Fuxy5AL9G62ZgBWE1ga8YVG8joQsKQzaaJE,2686
4
- android_notify/styles.py,sha256=OJBh-a2d_iOPcv50n_wUXezmh8Oc9MKDwM7c-RjkLAI,104
5
- android_notify-0.1.dist-info/METADATA,sha256=VN2Je_QPndtGpddzr99dnBwTv0jJr2BONTWJArZYgBU,140
6
- android_notify-0.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
7
- android_notify-0.1.dist-info/top_level.txt,sha256=IR1ONMrRSRINZpWn2X0dL5gbWwWINsK7PW8Jy2p4fU8,15
8
- android_notify-0.1.dist-info/RECORD,,