android-notify 0.2__tar.gz → 1.0__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.

@@ -0,0 +1,139 @@
1
+ Metadata-Version: 2.1
2
+ Name: android_notify
3
+ Version: 1.0
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
+ Project-URL: Funding, https://buymeacoffee.com/fector101
9
+ Project-URL: Source, https://github.com/Fector101/android_notify/
10
+ Requires-Python: >=3.6
11
+ Description-Content-Type: text/markdown
12
+
13
+ # Android Notify
14
+
15
+ `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.
16
+
17
+ ## Features
18
+
19
+ - Send Android notifications with custom titles and messages.
20
+ - Support for multiple notification styles:
21
+ - Big Text
22
+ - Big Picture
23
+ - Inbox
24
+ - Ability to include images in notifications.
25
+ - Compatible with Android 8.0+ (Notification Channels).
26
+ - Customizable notification channels.
27
+ - Support for large icons in notifications.
28
+
29
+ ## Installation
30
+
31
+ Make sure you have the required dependencies installed:
32
+
33
+ ```bash
34
+ pip install android-notify
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ **Prerequisites:**
40
+
41
+ - Buildozer
42
+ - Kivy
43
+
44
+ In your **`buildozer.spec`** file, ensure you include the following:
45
+
46
+ ```ini
47
+ # Add pyjnius so it's packaged with the build
48
+ requirements = python3,kivy,pyjnius
49
+
50
+ # Add permission for notifications
51
+ android.permissions = POST_NOTIFICATIONS
52
+
53
+ # Required dependencies (write exactly as shown, no quotation marks)
54
+ android.gradle_dependencies = androidx.core:core:1.6.0
55
+ android.enable_androidx = True
56
+ ```
57
+
58
+ ### Example Notification
59
+
60
+ ```python
61
+ from android_notify.core import send_notification
62
+
63
+ # Send a basic notification
64
+ send_notification("Hello", "This is a basic notification.")
65
+
66
+ # Send a notification with an image
67
+ send_notification(
68
+ title='Picture Alert!',
69
+ message='This notification includes an image.',
70
+ style='big_picture',
71
+ img_path='assets/imgs/icon.png'
72
+ )
73
+
74
+ # Send a notification with inbox style
75
+ send_notification(
76
+ title='Inbox Notification',
77
+ message='Line 1\nLine 2\nLine 3',
78
+ style='inbox'
79
+ )
80
+
81
+ # Send a Big Text notification (Note this send as a normal notification if not supported on said device)
82
+ send_notification(
83
+ title='Hello!',
84
+ message='This is a sample notification.',
85
+ style='big_text'
86
+ )
87
+ ```
88
+
89
+ ### Function Reference
90
+
91
+ #### `send_notification`
92
+
93
+ - **title** (*str*): Notification title.
94
+ - **message** (*str*): Notification message body.
95
+ - **style** (*str*): Notification style (`big_text`, `big_picture`, `inbox`, `large_icon`).
96
+ - **img_path** (*str*): Path to the image (for `big_picture` or `large_icon` styles).
97
+ - **channel_id** (*str*): Notification channel ID.
98
+
99
+ #### `get_image_uri`
100
+
101
+ - Resolves the absolute URI of an image resource.
102
+ - **relative_path** (*str*): The relative path to the image.
103
+
104
+ ### Advanced Usage
105
+
106
+ You can customize notification channels for different types of notifications.
107
+
108
+ ```python
109
+ send_notification(
110
+ title='Custom Channel Notification',
111
+ message='This uses a custom notification channel.',
112
+ channel_id='custom_channel'
113
+ )
114
+ ```
115
+
116
+ ## Contribution
117
+
118
+ Feel free to open issues or submit pull requests for improvements!
119
+
120
+ ## 🐛 Reporting Issues
121
+
122
+ Found a bug? Please open an issue on our [GitHub Issues](https://github.com/Fector101/android_notify/issues) page.
123
+
124
+ ## ☕ Support the Project
125
+
126
+ If you find TurboTask helpful, consider buying me a coffee! Your support helps maintain and improve the project.
127
+
128
+ <a href="https://www.buymeacoffee.com/fector101" target="_blank">
129
+ <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" height="60">
130
+ </a>
131
+
132
+ ## Author
133
+
134
+ - Fabian - <fector101@yahoo.com>
135
+ - GitHub: <https://github.com/Fector101/android_notify>
136
+
137
+ ## Acknowledgments
138
+
139
+ - Thanks to the Kivy and Pyjnius communities for their support.
@@ -0,0 +1,127 @@
1
+ # Android Notify
2
+
3
+ `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.
4
+
5
+ ## Features
6
+
7
+ - Send Android notifications with custom titles and messages.
8
+ - Support for multiple notification styles:
9
+ - Big Text
10
+ - Big Picture
11
+ - Inbox
12
+ - Ability to include images in notifications.
13
+ - Compatible with Android 8.0+ (Notification Channels).
14
+ - Customizable notification channels.
15
+ - Support for large icons in notifications.
16
+
17
+ ## Installation
18
+
19
+ Make sure you have the required dependencies installed:
20
+
21
+ ```bash
22
+ pip install android-notify
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ **Prerequisites:**
28
+
29
+ - Buildozer
30
+ - Kivy
31
+
32
+ In your **`buildozer.spec`** file, ensure you include the following:
33
+
34
+ ```ini
35
+ # Add pyjnius so it's packaged with the build
36
+ requirements = python3,kivy,pyjnius
37
+
38
+ # Add permission for notifications
39
+ android.permissions = POST_NOTIFICATIONS
40
+
41
+ # Required dependencies (write exactly as shown, no quotation marks)
42
+ android.gradle_dependencies = androidx.core:core:1.6.0
43
+ android.enable_androidx = True
44
+ ```
45
+
46
+ ### Example Notification
47
+
48
+ ```python
49
+ from android_notify.core import send_notification
50
+
51
+ # Send a basic notification
52
+ send_notification("Hello", "This is a basic notification.")
53
+
54
+ # Send a notification with an image
55
+ send_notification(
56
+ title='Picture Alert!',
57
+ message='This notification includes an image.',
58
+ style='big_picture',
59
+ img_path='assets/imgs/icon.png'
60
+ )
61
+
62
+ # Send a notification with inbox style
63
+ send_notification(
64
+ title='Inbox Notification',
65
+ message='Line 1\nLine 2\nLine 3',
66
+ style='inbox'
67
+ )
68
+
69
+ # Send a Big Text notification (Note this send as a normal notification if not supported on said device)
70
+ send_notification(
71
+ title='Hello!',
72
+ message='This is a sample notification.',
73
+ style='big_text'
74
+ )
75
+ ```
76
+
77
+ ### Function Reference
78
+
79
+ #### `send_notification`
80
+
81
+ - **title** (*str*): Notification title.
82
+ - **message** (*str*): Notification message body.
83
+ - **style** (*str*): Notification style (`big_text`, `big_picture`, `inbox`, `large_icon`).
84
+ - **img_path** (*str*): Path to the image (for `big_picture` or `large_icon` styles).
85
+ - **channel_id** (*str*): Notification channel ID.
86
+
87
+ #### `get_image_uri`
88
+
89
+ - Resolves the absolute URI of an image resource.
90
+ - **relative_path** (*str*): The relative path to the image.
91
+
92
+ ### Advanced Usage
93
+
94
+ You can customize notification channels for different types of notifications.
95
+
96
+ ```python
97
+ send_notification(
98
+ title='Custom Channel Notification',
99
+ message='This uses a custom notification channel.',
100
+ channel_id='custom_channel'
101
+ )
102
+ ```
103
+
104
+ ## Contribution
105
+
106
+ Feel free to open issues or submit pull requests for improvements!
107
+
108
+ ## 🐛 Reporting Issues
109
+
110
+ Found a bug? Please open an issue on our [GitHub Issues](https://github.com/Fector101/android_notify/issues) page.
111
+
112
+ ## ☕ Support the Project
113
+
114
+ If you find TurboTask helpful, consider buying me a coffee! Your support helps maintain and improve the project.
115
+
116
+ <a href="https://www.buymeacoffee.com/fector101" target="_blank">
117
+ <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" height="60">
118
+ </a>
119
+
120
+ ## Author
121
+
122
+ - Fabian - <fector101@yahoo.com>
123
+ - GitHub: <https://github.com/Fector101/android_notify>
124
+
125
+ ## Acknowledgments
126
+
127
+ - Thanks to the Kivy and Pyjnius communities for their support.
@@ -0,0 +1,168 @@
1
+
2
+ from jnius import autoclass,cast
3
+ import random
4
+ import os
5
+
6
+
7
+ def asks_permission_if_needed():
8
+ """
9
+ Ask for permission to send notifications if needed.
10
+ """
11
+ # Get the required Java classes
12
+ from android.permissions import request_permissions, Permission,check_permission # type: ignore
13
+
14
+ def check_permissions(permissions):
15
+ for permission in permissions:
16
+ if check_permission(permission) != True:
17
+ return False
18
+ return True
19
+
20
+ permissions=[Permission.POST_NOTIFICATIONS]
21
+ if check_permissions(permissions):
22
+ request_permissions(permissions)
23
+
24
+ def get_image_uri(relative_path):
25
+ """
26
+ Get the absolute URI for an image in the assets folder.
27
+ :param relative_path: The relative path to the image (e.g., 'assets/imgs/icon.png').
28
+ :return: Absolute URI java Object (e.g., 'file:///path/to/file.png').
29
+ """
30
+ from android.storage import app_storage_path # type: ignore
31
+ # print("app_storage_path()",app_storage_path())
32
+
33
+ output_path = os.path.join(app_storage_path(),'app', relative_path)
34
+ # print(output_path,'output_path') # /data/user/0/org.laner.lan_ft/files/app/assets/imgs/icon.png
35
+
36
+ Uri = autoclass('android.net.Uri')
37
+ return Uri.parse(f"file://{output_path}")
38
+
39
+ def send_notification(title, message, style=None, img_path=None, channel_id="default_channel"):
40
+ """
41
+ Send a notification on Android.
42
+
43
+ :param title: Title of the notification.
44
+ :param message: Message body.
45
+ :param style: Style of the notification ('big_text', 'big_picture', 'inbox').
46
+ :param image: Image URL or drawable for 'big_picture' style.
47
+ :param channel_id: Notification channel ID.
48
+ """
49
+ # TODO check if running on android short circuit and return message if not
50
+
51
+ # Get the required Java classes
52
+ # Notification Base
53
+ PythonActivity = autoclass('org.kivy.android.PythonActivity')
54
+ NotificationChannel = autoclass('android.app.NotificationChannel')
55
+ String = autoclass('java.lang.String')
56
+
57
+
58
+ NotificationManagerCompat = autoclass('androidx.core.app.NotificationManagerCompat')
59
+ NotificationCompat = autoclass('androidx.core.app.NotificationCompat')
60
+
61
+ # Notification Design
62
+ NotificationCompatBuilder = autoclass('androidx.core.app.NotificationCompat$Builder')
63
+ NotificationCompatBigTextStyle = autoclass('androidx.core.app.NotificationCompat$BigTextStyle')
64
+ # NotificationCompatBigTextStyle = autoclass('android.app.Notification$BigTextStyle')
65
+
66
+ NotificationCompatBigPictureStyle = autoclass('androidx.core.app.NotificationCompat$BigPictureStyle')
67
+ NotificationCompatInboxStyle = autoclass('androidx.core.app.NotificationCompat$InboxStyle')
68
+ BitmapFactory = autoclass('android.graphics.BitmapFactory')
69
+ BuildVersion = autoclass('android.os.Build$VERSION')
70
+ PendingIntent = autoclass('android.app.PendingIntent')
71
+ Intent = autoclass('android.content.Intent')
72
+
73
+ # Get the app's context and notification manager
74
+ context = PythonActivity.mActivity
75
+ notification_manager = context.getSystemService(context.NOTIFICATION_SERVICE)
76
+
77
+ importance= NotificationManagerCompat.IMPORTANCE_HIGH #autoclass('android.app.NotificationManager').IMPORTANCE_HIGH also works #NotificationManager.IMPORTANCE_DEFAULT
78
+
79
+ # Notification Channel (Required for Android 8.0+)
80
+ if BuildVersion.SDK_INT >= 26:
81
+ print('entered....')
82
+ channel = NotificationChannel(
83
+ channel_id,
84
+ "Default Channel",
85
+ importance
86
+ )
87
+ notification_manager.createNotificationChannel(channel)
88
+
89
+ # Build the notification
90
+ builder = NotificationCompatBuilder(context, channel_id)
91
+ builder.setContentTitle(title)
92
+ builder.setContentText(message)
93
+ builder.setSmallIcon(context.getApplicationInfo().icon)
94
+ builder.setDefaults(NotificationCompat.DEFAULT_ALL)
95
+ builder.setPriority(NotificationCompat.PRIORITY_HIGH)
96
+
97
+ # Get Image
98
+ img=img_path
99
+ if img_path:
100
+ try:
101
+ img = get_image_uri(img_path)
102
+ except Exception as e:
103
+ print('Failed getting Image path',e)
104
+
105
+ # Add Actions (Buttons)
106
+
107
+ # add Action 1 Button
108
+ # try:
109
+ # # Create Action 1
110
+ # action_intent = Intent(context, PythonActivity)
111
+ # action_intent.setAction("ACTION_ONE")
112
+ # pending_action_intent = PendingIntent.getActivity(
113
+ # context,
114
+ # 0,
115
+ # action_intent,
116
+ # PendingIntent.FLAG_IMMUTABLE
117
+ # )
118
+
119
+ # # Convert text to CharSequence
120
+ # action_text = cast('java.lang.CharSequence', String("Action 1"))
121
+
122
+ # # Add action with proper types
123
+ # builder.addAction(
124
+ # int(context.getApplicationInfo().icon), # Cast icon to int
125
+ # action_text, # CharSequence text
126
+ # pending_action_intent # PendingIntent
127
+ # )
128
+
129
+
130
+ # # Set content intent for notification tap
131
+ # builder.setContentIntent(pending_action_intent)
132
+ # except Exception as e:
133
+ # print('Failed adding Action 1',e)
134
+
135
+
136
+ # Apply styles
137
+ if style == "big_text":
138
+ big_text_style = NotificationCompatBigTextStyle()
139
+ big_text_style.bigText(message)
140
+ builder.setStyle(big_text_style)
141
+
142
+
143
+ elif style == "big_picture" and img_path:
144
+ try:
145
+ bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(img))
146
+ # bitmap = BitmapFactory.decodeFile(img_path)
147
+ builder.setLargeIcon(bitmap)
148
+ big_picture_style = NotificationCompatBigPictureStyle().bigPicture(bitmap)
149
+ # big_picture_style.bigPicture(bitmap).bigLargeIcon(None)
150
+ # big_picture_style.bigLargeIcon(bitmap) # This just changes dropdown app icon
151
+
152
+ builder.setStyle(big_picture_style)
153
+ except Exception as e:
154
+ print('Failed Adding Bitmap...', e)
155
+ elif style == "inbox":
156
+ inbox_style = NotificationCompatInboxStyle()
157
+ for line in message.split("\n"):
158
+ inbox_style.addLine(line)
159
+ builder.setStyle(inbox_style)
160
+ elif style == "large_icon" and img_path:
161
+ try:
162
+ bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(img))
163
+ builder.setLargeIcon(bitmap)
164
+ except Exception as e:
165
+ print('Failed Large Icon...', e)
166
+
167
+ # Show the notification
168
+ notification_manager.notify(random.randint(0, 100), builder.build())
@@ -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,139 @@
1
+ Metadata-Version: 2.1
2
+ Name: android-notify
3
+ Version: 1.0
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
+ Project-URL: Funding, https://buymeacoffee.com/fector101
9
+ Project-URL: Source, https://github.com/Fector101/android_notify/
10
+ Requires-Python: >=3.6
11
+ Description-Content-Type: text/markdown
12
+
13
+ # Android Notify
14
+
15
+ `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.
16
+
17
+ ## Features
18
+
19
+ - Send Android notifications with custom titles and messages.
20
+ - Support for multiple notification styles:
21
+ - Big Text
22
+ - Big Picture
23
+ - Inbox
24
+ - Ability to include images in notifications.
25
+ - Compatible with Android 8.0+ (Notification Channels).
26
+ - Customizable notification channels.
27
+ - Support for large icons in notifications.
28
+
29
+ ## Installation
30
+
31
+ Make sure you have the required dependencies installed:
32
+
33
+ ```bash
34
+ pip install android-notify
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ **Prerequisites:**
40
+
41
+ - Buildozer
42
+ - Kivy
43
+
44
+ In your **`buildozer.spec`** file, ensure you include the following:
45
+
46
+ ```ini
47
+ # Add pyjnius so it's packaged with the build
48
+ requirements = python3,kivy,pyjnius
49
+
50
+ # Add permission for notifications
51
+ android.permissions = POST_NOTIFICATIONS
52
+
53
+ # Required dependencies (write exactly as shown, no quotation marks)
54
+ android.gradle_dependencies = androidx.core:core:1.6.0
55
+ android.enable_androidx = True
56
+ ```
57
+
58
+ ### Example Notification
59
+
60
+ ```python
61
+ from android_notify.core import send_notification
62
+
63
+ # Send a basic notification
64
+ send_notification("Hello", "This is a basic notification.")
65
+
66
+ # Send a notification with an image
67
+ send_notification(
68
+ title='Picture Alert!',
69
+ message='This notification includes an image.',
70
+ style='big_picture',
71
+ img_path='assets/imgs/icon.png'
72
+ )
73
+
74
+ # Send a notification with inbox style
75
+ send_notification(
76
+ title='Inbox Notification',
77
+ message='Line 1\nLine 2\nLine 3',
78
+ style='inbox'
79
+ )
80
+
81
+ # Send a Big Text notification (Note this send as a normal notification if not supported on said device)
82
+ send_notification(
83
+ title='Hello!',
84
+ message='This is a sample notification.',
85
+ style='big_text'
86
+ )
87
+ ```
88
+
89
+ ### Function Reference
90
+
91
+ #### `send_notification`
92
+
93
+ - **title** (*str*): Notification title.
94
+ - **message** (*str*): Notification message body.
95
+ - **style** (*str*): Notification style (`big_text`, `big_picture`, `inbox`, `large_icon`).
96
+ - **img_path** (*str*): Path to the image (for `big_picture` or `large_icon` styles).
97
+ - **channel_id** (*str*): Notification channel ID.
98
+
99
+ #### `get_image_uri`
100
+
101
+ - Resolves the absolute URI of an image resource.
102
+ - **relative_path** (*str*): The relative path to the image.
103
+
104
+ ### Advanced Usage
105
+
106
+ You can customize notification channels for different types of notifications.
107
+
108
+ ```python
109
+ send_notification(
110
+ title='Custom Channel Notification',
111
+ message='This uses a custom notification channel.',
112
+ channel_id='custom_channel'
113
+ )
114
+ ```
115
+
116
+ ## Contribution
117
+
118
+ Feel free to open issues or submit pull requests for improvements!
119
+
120
+ ## 🐛 Reporting Issues
121
+
122
+ Found a bug? Please open an issue on our [GitHub Issues](https://github.com/Fector101/android_notify/issues) page.
123
+
124
+ ## ☕ Support the Project
125
+
126
+ If you find TurboTask helpful, consider buying me a coffee! Your support helps maintain and improve the project.
127
+
128
+ <a href="https://www.buymeacoffee.com/fector101" target="_blank">
129
+ <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" height="60">
130
+ </a>
131
+
132
+ ## Author
133
+
134
+ - Fabian - <fector101@yahoo.com>
135
+ - GitHub: <https://github.com/Fector101/android_notify>
136
+
137
+ ## Acknowledgments
138
+
139
+ - Thanks to the Kivy and Pyjnius communities for their support.
@@ -0,0 +1,19 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name='android_notify',
5
+ version='1.0',
6
+ author='Fabian',
7
+ url='https://github.com/Fector101/android_notify/',
8
+ description='A Python package for sending Android notifications.',
9
+ packages=find_packages(),
10
+ install_requires=['pyjnius'],
11
+ author_email='fabianjoseph063@gmail.com',
12
+ long_description=open("README.md").read(),
13
+ long_description_content_type="text/markdown",
14
+ python_requires='>=3.6',
15
+ project_urls={
16
+ 'Funding': 'https://buymeacoffee.com/fector101',
17
+ 'Source': 'https://github.com/Fector101/android_notify/',
18
+ },
19
+ )
@@ -1,4 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: android_notify
3
- Version: 0.2
4
- Summary: A Python package for sending Android notifications.
@@ -1,26 +0,0 @@
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
- ```
@@ -1,100 +0,0 @@
1
- from jnius import autoclass
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)
35
-
36
- def send_notification(title, message, style=None, img_path=None, channel_id="default_channel"):
37
- """
38
- Send a notification on Android.
39
-
40
- :param title: Title of the notification.
41
- :param message: Message body.
42
- :param style: Style of the notification ('big_text', 'big_picture', 'inbox').
43
- :param image: Image URL or drawable for 'big_picture' style.
44
- :param channel_id: Notification channel ID.
45
- """
46
- # Get the required Java classes
47
- PythonActivity = autoclass('org.kivy.android.PythonActivity')
48
- NotificationManager = autoclass('android.app.NotificationManager')
49
- NotificationChannel = autoclass('android.app.NotificationChannel')
50
- NotificationCompatBuilder = autoclass('androidx.core.app.NotificationCompat$Builder')
51
- NotificationCompatBigTextStyle = autoclass('androidx.core.app.NotificationCompat$BigTextStyle')
52
- NotificationCompatBigPictureStyle = autoclass('androidx.core.app.NotificationCompat$BigPictureStyle')
53
- NotificationCompatInboxStyle = autoclass('androidx.core.app.NotificationCompat$InboxStyle')
54
- BitmapFactory = autoclass('android.graphics.BitmapFactory')
55
-
56
- # Get the app's context and notification manager
57
- context = PythonActivity.mActivity
58
- notification_manager = context.getSystemService(context.NOTIFICATION_SERVICE)
59
-
60
- # Notification Channel (Required for Android 8.0+)
61
- if notification_manager.getNotificationChannel(channel_id) is None:
62
- channel = NotificationChannel(
63
- channel_id,
64
- "Default Channel",
65
- NotificationManager.IMPORTANCE_DEFAULT
66
- )
67
- notification_manager.createNotificationChannel(channel)
68
-
69
- # Build the notification
70
- builder = NotificationCompatBuilder(context, channel_id)
71
- builder.setContentTitle(title)
72
- builder.setContentText(message)
73
- builder.setSmallIcon(context.getApplicationInfo().icon)
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
-
83
- # Apply styles
84
- if style == "big_text":
85
- big_text_style = NotificationCompatBigTextStyle()
86
- big_text_style.bigText(message)
87
- builder.setStyle(big_text_style)
88
- 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)
93
- elif style == "inbox":
94
- inbox_style = NotificationCompatInboxStyle()
95
- for line in message.split("\n"):
96
- inbox_style.addLine(line)
97
- builder.setStyle(inbox_style)
98
-
99
- # Show the notification
100
- notification_manager.notify(random.randint(0, 100), builder.build())
@@ -1,4 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: android-notify
3
- Version: 0.2
4
- Summary: A Python package for sending Android notifications.
@@ -1,9 +0,0 @@
1
- from setuptools import setup, find_packages
2
-
3
- setup(
4
- name='android_notify',
5
- version='0.2',
6
- description='A Python package for sending Android notifications.',
7
- packages=find_packages(),
8
- install_requires=['pyjnius'],
9
- )
File without changes