android-notify 0.1__tar.gz → 0.3__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,115 @@
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
+
11
+ # Android Notify
12
+
13
+ `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.
14
+
15
+ ## Features
16
+
17
+ - Send Android notifications with custom titles and messages.
18
+ - Support for multiple notification styles:
19
+ - Big Text
20
+ - Big Picture
21
+ - Inbox
22
+ - Ability to include images in notifications.
23
+ - Compatible with Android 8.0+ (Notification Channels).
24
+ - Customizable notification channels.
25
+ - Support for large icons in notifications.
26
+
27
+ ## Installation
28
+
29
+ Make sure you have the required dependencies installed:
30
+
31
+ ```bash
32
+ pip install android_notify
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ### Example Notification
38
+
39
+ ```python
40
+ from android_notify.core import send_notification
41
+
42
+ # Send a basic notification
43
+ send_notification(
44
+ title='Hello!',
45
+ message='This is a sample notification.',
46
+ style='big_text'
47
+ )
48
+
49
+ # Send a notification with an image
50
+ send_notification(
51
+ title='Picture Alert!',
52
+ message='This notification includes an image.',
53
+ style='big_picture',
54
+ img_path='assets/imgs/icon.png'
55
+ )
56
+
57
+ # Send a notification with inbox style
58
+ send_notification(
59
+ title='Inbox Notification',
60
+ message='Line 1\nLine 2\nLine 3',
61
+ style='inbox'
62
+ )
63
+ ```
64
+
65
+ ### Function Reference
66
+
67
+ #### `send_notification`
68
+
69
+ - **title** (*str*): Notification title.
70
+ - **message** (*str*): Notification message body.
71
+ - **style** (*str*): Notification style (`big_text`, `big_picture`, `inbox`, `large_icon`).
72
+ - **img_path** (*str*): Path to the image (for `big_picture` or `large_icon` styles).
73
+ - **channel_id** (*str*): Notification channel ID.
74
+
75
+ #### `get_image_uri`
76
+
77
+ - Resolves the absolute URI of an image resource.
78
+ - **relative_path** (*str*): The relative path to the image.
79
+
80
+ ### Advanced Usage
81
+
82
+ You can customize notification channels for different types of notifications.
83
+
84
+ ```python
85
+ send_notification(
86
+ title='Custom Channel Notification',
87
+ message='This uses a custom notification channel.',
88
+ channel_id='custom_channel'
89
+ )
90
+ ```
91
+
92
+ ## Requirements
93
+
94
+ - Python 3.x
95
+ - Kivy
96
+ - Pyjnius
97
+ - Android SDK (For building APKs)
98
+
99
+ ## License
100
+
101
+ This project is licensed under the MIT License.
102
+
103
+ ## Contribution
104
+
105
+ Feel free to open issues or submit pull requests for improvements!
106
+
107
+ ## Author
108
+
109
+ **Fabian** - *Full-Stack Developer* 🚀
110
+
111
+ ## Acknowledgments
112
+
113
+ - Thanks to the Kivy and Pyjnius communities for their support.
114
+ - Inspired by modern Android notification practices.
115
+
@@ -0,0 +1,105 @@
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
+ ### Example Notification
28
+
29
+ ```python
30
+ from android_notify.core import send_notification
31
+
32
+ # Send a basic notification
33
+ send_notification(
34
+ title='Hello!',
35
+ message='This is a sample notification.',
36
+ style='big_text'
37
+ )
38
+
39
+ # Send a notification with an image
40
+ send_notification(
41
+ title='Picture Alert!',
42
+ message='This notification includes an image.',
43
+ style='big_picture',
44
+ img_path='assets/imgs/icon.png'
45
+ )
46
+
47
+ # Send a notification with inbox style
48
+ send_notification(
49
+ title='Inbox Notification',
50
+ message='Line 1\nLine 2\nLine 3',
51
+ style='inbox'
52
+ )
53
+ ```
54
+
55
+ ### Function Reference
56
+
57
+ #### `send_notification`
58
+
59
+ - **title** (*str*): Notification title.
60
+ - **message** (*str*): Notification message body.
61
+ - **style** (*str*): Notification style (`big_text`, `big_picture`, `inbox`, `large_icon`).
62
+ - **img_path** (*str*): Path to the image (for `big_picture` or `large_icon` styles).
63
+ - **channel_id** (*str*): Notification channel ID.
64
+
65
+ #### `get_image_uri`
66
+
67
+ - Resolves the absolute URI of an image resource.
68
+ - **relative_path** (*str*): The relative path to the image.
69
+
70
+ ### Advanced Usage
71
+
72
+ You can customize notification channels for different types of notifications.
73
+
74
+ ```python
75
+ send_notification(
76
+ title='Custom Channel Notification',
77
+ message='This uses a custom notification channel.',
78
+ channel_id='custom_channel'
79
+ )
80
+ ```
81
+
82
+ ## Requirements
83
+
84
+ - Python 3.x
85
+ - Kivy
86
+ - Pyjnius
87
+ - Android SDK (For building APKs)
88
+
89
+ ## License
90
+
91
+ This project is licensed under the MIT License.
92
+
93
+ ## Contribution
94
+
95
+ Feel free to open issues or submit pull requests for improvements!
96
+
97
+ ## Author
98
+
99
+ **Fabian** - *Full-Stack Developer* 🚀
100
+
101
+ ## Acknowledgments
102
+
103
+ - Thanks to the Kivy and Pyjnius communities for their support.
104
+ - Inspired by modern Android notification practices.
105
+
@@ -0,0 +1,150 @@
1
+
2
+ from jnius import autoclass,cast
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())
14
+
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"):
22
+ """
23
+ Send a notification on Android.
24
+
25
+ :param title: Title of the notification.
26
+ :param message: Message body.
27
+ :param style: Style of the notification ('big_text', 'big_picture', 'inbox').
28
+ :param image: Image URL or drawable for 'big_picture' style.
29
+ :param channel_id: Notification channel ID.
30
+ """
31
+ # TODO check if running on android short circuit and return message if not
32
+
33
+ # Get the required Java classes
34
+ # Notification Base
35
+ PythonActivity = autoclass('org.kivy.android.PythonActivity')
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
44
+ NotificationCompatBuilder = autoclass('androidx.core.app.NotificationCompat$Builder')
45
+ NotificationCompatBigTextStyle = autoclass('androidx.core.app.NotificationCompat$BigTextStyle')
46
+ # NotificationCompatBigTextStyle = autoclass('android.app.Notification$BigTextStyle')
47
+
48
+ NotificationCompatBigPictureStyle = autoclass('androidx.core.app.NotificationCompat$BigPictureStyle')
49
+ NotificationCompatInboxStyle = autoclass('androidx.core.app.NotificationCompat$InboxStyle')
50
+ BitmapFactory = autoclass('android.graphics.BitmapFactory')
51
+ BuildVersion = autoclass('android.os.Build$VERSION')
52
+ PendingIntent = autoclass('android.app.PendingIntent')
53
+ Intent = autoclass('android.content.Intent')
54
+
55
+ # Get the app's context and notification manager
56
+ context = PythonActivity.mActivity
57
+ notification_manager = context.getSystemService(context.NOTIFICATION_SERVICE)
58
+
59
+ importance= NotificationManagerCompat.IMPORTANCE_HIGH #autoclass('android.app.NotificationManager').IMPORTANCE_HIGH also works #NotificationManager.IMPORTANCE_DEFAULT
60
+
61
+ # Notification Channel (Required for Android 8.0+)
62
+ if BuildVersion.SDK_INT >= 26:
63
+ print('entered....')
64
+ channel = NotificationChannel(
65
+ channel_id,
66
+ "Default Channel",
67
+ importance
68
+ )
69
+ notification_manager.createNotificationChannel(channel)
70
+
71
+ # Build the notification
72
+ builder = NotificationCompatBuilder(context, channel_id)
73
+ builder.setContentTitle(title)
74
+ builder.setContentText(message)
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)
116
+
117
+
118
+ # Apply styles
119
+ if style == "big_text":
120
+ big_text_style = NotificationCompatBigTextStyle()
121
+ big_text_style.bigText(message)
122
+ builder.setStyle(big_text_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)
137
+ elif style == "inbox":
138
+ inbox_style = NotificationCompatInboxStyle()
139
+ for line in message.split("\n"):
140
+ inbox_style.addLine(line)
141
+ builder.setStyle(inbox_style)
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
+
149
+ # Show the notification
150
+ 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,115 @@
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
+
11
+ # Android Notify
12
+
13
+ `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.
14
+
15
+ ## Features
16
+
17
+ - Send Android notifications with custom titles and messages.
18
+ - Support for multiple notification styles:
19
+ - Big Text
20
+ - Big Picture
21
+ - Inbox
22
+ - Ability to include images in notifications.
23
+ - Compatible with Android 8.0+ (Notification Channels).
24
+ - Customizable notification channels.
25
+ - Support for large icons in notifications.
26
+
27
+ ## Installation
28
+
29
+ Make sure you have the required dependencies installed:
30
+
31
+ ```bash
32
+ pip install android_notify
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ### Example Notification
38
+
39
+ ```python
40
+ from android_notify.core import send_notification
41
+
42
+ # Send a basic notification
43
+ send_notification(
44
+ title='Hello!',
45
+ message='This is a sample notification.',
46
+ style='big_text'
47
+ )
48
+
49
+ # Send a notification with an image
50
+ send_notification(
51
+ title='Picture Alert!',
52
+ message='This notification includes an image.',
53
+ style='big_picture',
54
+ img_path='assets/imgs/icon.png'
55
+ )
56
+
57
+ # Send a notification with inbox style
58
+ send_notification(
59
+ title='Inbox Notification',
60
+ message='Line 1\nLine 2\nLine 3',
61
+ style='inbox'
62
+ )
63
+ ```
64
+
65
+ ### Function Reference
66
+
67
+ #### `send_notification`
68
+
69
+ - **title** (*str*): Notification title.
70
+ - **message** (*str*): Notification message body.
71
+ - **style** (*str*): Notification style (`big_text`, `big_picture`, `inbox`, `large_icon`).
72
+ - **img_path** (*str*): Path to the image (for `big_picture` or `large_icon` styles).
73
+ - **channel_id** (*str*): Notification channel ID.
74
+
75
+ #### `get_image_uri`
76
+
77
+ - Resolves the absolute URI of an image resource.
78
+ - **relative_path** (*str*): The relative path to the image.
79
+
80
+ ### Advanced Usage
81
+
82
+ You can customize notification channels for different types of notifications.
83
+
84
+ ```python
85
+ send_notification(
86
+ title='Custom Channel Notification',
87
+ message='This uses a custom notification channel.',
88
+ channel_id='custom_channel'
89
+ )
90
+ ```
91
+
92
+ ## Requirements
93
+
94
+ - Python 3.x
95
+ - Kivy
96
+ - Pyjnius
97
+ - Android SDK (For building APKs)
98
+
99
+ ## License
100
+
101
+ This project is licensed under the MIT License.
102
+
103
+ ## Contribution
104
+
105
+ Feel free to open issues or submit pull requests for improvements!
106
+
107
+ ## Author
108
+
109
+ **Fabian** - *Full-Stack Developer* 🚀
110
+
111
+ ## Acknowledgments
112
+
113
+ - Thanks to the Kivy and Pyjnius communities for their support.
114
+ - Inspired by modern Android notification practices.
115
+
@@ -0,0 +1,15 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name='android_notify',
5
+ version='0.3',
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
+ )
@@ -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,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,60 +0,0 @@
1
- from jnius import autoclass
2
- import random
3
-
4
- def send_notification(title, message, style=None, image=None, channel_id="default_channel"):
5
- """
6
- Send a notification on Android.
7
-
8
- :param title: Title of the notification.
9
- :param message: Message body.
10
- :param style: Style of the notification ('big_text', 'big_picture', 'inbox').
11
- :param image: Image URL or drawable for 'big_picture' style.
12
- :param channel_id: Notification channel ID.
13
- """
14
- # Get the required Java classes
15
- PythonActivity = autoclass('org.kivy.android.PythonActivity')
16
- NotificationManager = autoclass('android.app.NotificationManager')
17
- NotificationChannel = autoclass('android.app.NotificationChannel')
18
- NotificationCompatBuilder = autoclass('androidx.core.app.NotificationCompat$Builder')
19
- NotificationCompatBigTextStyle = autoclass('androidx.core.app.NotificationCompat$BigTextStyle')
20
- NotificationCompatBigPictureStyle = autoclass('androidx.core.app.NotificationCompat$BigPictureStyle')
21
- NotificationCompatInboxStyle = autoclass('androidx.core.app.NotificationCompat$InboxStyle')
22
- BitmapFactory = autoclass('android.graphics.BitmapFactory')
23
-
24
- # Get the app's context and notification manager
25
- context = PythonActivity.mActivity
26
- notification_manager = context.getSystemService(context.NOTIFICATION_SERVICE)
27
-
28
- # Notification Channel (Required for Android 8.0+)
29
- if notification_manager.getNotificationChannel(channel_id) is None:
30
- channel = NotificationChannel(
31
- channel_id,
32
- "Default Channel",
33
- NotificationManager.IMPORTANCE_DEFAULT
34
- )
35
- notification_manager.createNotificationChannel(channel)
36
-
37
- # Build the notification
38
- builder = NotificationCompatBuilder(context, channel_id)
39
- builder.setContentTitle(title)
40
- builder.setContentText(message)
41
- builder.setSmallIcon(context.getApplicationInfo().icon)
42
-
43
- # Apply styles
44
- if style == "big_text":
45
- big_text_style = NotificationCompatBigTextStyle()
46
- big_text_style.bigText(message)
47
- 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)
53
- elif style == "inbox":
54
- inbox_style = NotificationCompatInboxStyle()
55
- for line in message.split("\n"):
56
- inbox_style.addLine(line)
57
- builder.setStyle(inbox_style)
58
-
59
- # Show the notification
60
- notification_manager.notify(random.randint(0, 100), builder.build())
@@ -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,9 +0,0 @@
1
- from setuptools import setup, find_packages
2
-
3
- setup(
4
- name='android_notify',
5
- version='0.1',
6
- description='A Python package for sending Android notifications.',
7
- packages=find_packages(),
8
- install_requires=['pyjnius'],
9
- )
File without changes