Skip to content

Commit 19dcf8a

Browse files
committed
docs: making suredocs match APIs
1 parent b3c6732 commit 19dcf8a

2 files changed

Lines changed: 44 additions & 23 deletions

File tree

docs/examples/flet-working/src/core.py

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def get_image_uri(relative_path):
9595
"""
9696
app_root_path = get_app_root_path()
9797
output_path = os.path.join(app_root_path,'app', relative_path)
98-
print(output_path,'output_path') # /data/user/0/org.laner.lan_ft/files/app/assets/imgs/icon.png
98+
# print(output_path,'output_path') # /data/user/0/org.laner.lan_ft/files/app/assets/imgs/icon.png
9999

100100
if not os.path.exists(output_path):
101101
raise FileNotFoundError(f"\nImage not found at path: {output_path}\n")
@@ -120,6 +120,7 @@ def insert_app_icon(builder,custom_icon_path):
120120
print('android_notify- error: ',e)
121121
builder.setSmallIcon(context.getApplicationInfo().icon)
122122
else:
123+
print('Found res icon -->',context.getApplicationInfo().icon,'<--')
123124
builder.setSmallIcon(context.getApplicationInfo().icon)
124125

125126
def send_notification(
@@ -129,7 +130,12 @@ def send_notification(
129130
img_path=None,
130131
channel_name="Default Channel",
131132
channel_id:str="default_channel",
132-
custom_app_icon="",
133+
custom_app_icon_path="",
134+
135+
big_picture_path='',
136+
large_icon_path='',
137+
big_text="",
138+
lines=""
133139
):
134140
"""
135141
Send a notification on Android.
@@ -143,15 +149,15 @@ def send_notification(
143149
if not ON_ANDROID:
144150
print('This Package Only Runs on Android !!! ---> Check "https://github.com/Fector101/android_notify/" for Documentation.')
145151
return
146-
152+
147153
asks_permission_if_needed()
148154
channel_id=channel_name.replace(' ','_').lower().lower() if not channel_id else channel_id
149155
# Get notification manager
150156
notification_manager = context.getSystemService(context.NOTIFICATION_SERVICE)
151157

152158
# importance= autoclass('android.app.NotificationManager').IMPORTANCE_HIGH # also works #NotificationManager.IMPORTANCE_DEFAULT
153159
importance= NotificationManagerCompat.IMPORTANCE_HIGH #autoclass('android.app.NotificationManager').IMPORTANCE_HIGH also works #NotificationManager.IMPORTANCE_DEFAULT
154-
160+
155161
# Notification Channel (Required for Android 8.0+)
156162
if BuildVersion.SDK_INT >= 26:
157163
channel = NotificationChannel(channel_id, channel_name,importance)
@@ -161,38 +167,53 @@ def send_notification(
161167
builder = NotificationCompatBuilder(context, channel_id)
162168
builder.setContentTitle(title)
163169
builder.setContentText(message)
164-
insert_app_icon(builder,custom_app_icon)
170+
insert_app_icon(builder,custom_app_icon_path)
165171
builder.setDefaults(NotificationCompat.DEFAULT_ALL)
166172
builder.setPriority(NotificationCompat.PRIORITY_HIGH)
167-
168-
img=None
173+
169174
if img_path:
175+
print('android_notify- img_path arg deprecated use "large_icon_path or big_picture_path or custom_app_icon_path"instead ')
176+
177+
big_picture = None
178+
if big_picture_path:
170179
try:
171-
img = get_image_uri(img_path)
180+
big_picture = get_image_uri(big_picture_path)
172181
except FileNotFoundError as e:
173-
print('Failed Adding Bitmap: ',e)
174-
182+
print('android_notify- Error Getting Uri for big_picture_path: ',e)
183+
184+
large_icon = None
185+
if large_icon_path:
186+
try:
187+
large_icon = get_image_uri(large_icon_path)
188+
except FileNotFoundError as e:
189+
print('android_notify- Error Getting Uri for large_icon_path: ',e)
190+
191+
175192
# Apply notification styles
176193
try:
177-
if style == "big_text":
194+
if big_text:
178195
big_text_style = NotificationCompatBigTextStyle()
179-
big_text_style.bigText(message)
196+
big_text_style.bigText(big_text)
180197
builder.setStyle(big_text_style)
181-
elif style == "big_picture" and img_path:
182-
bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(img))
183-
builder.setLargeIcon(bitmap)
184-
big_picture_style = NotificationCompatBigPictureStyle().bigPicture(bitmap)
185-
builder.setStyle(big_picture_style)
186-
elif style == "inbox":
198+
199+
elif lines:
187200
inbox_style = NotificationCompatInboxStyle()
188-
for line in message.split("\n"):
201+
for line in lines.split("\n"):
189202
inbox_style.addLine(line)
190203
builder.setStyle(inbox_style)
191-
elif style == "large_icon" and img_path:
192-
bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(img))
204+
205+
if large_icon:
206+
bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(large_icon))
207+
builder.setLargeIcon(bitmap)
208+
209+
if big_picture:
210+
bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(big_picture))
193211
builder.setLargeIcon(bitmap)
212+
big_picture_style = NotificationCompatBigPictureStyle().bigPicture(bitmap)
213+
builder.setStyle(big_picture_style)
214+
194215
except Exception as e:
195-
print('Failed Adding Style: ',e)
216+
print('android_notify- Error Failed Adding Style: ',e)
196217
# Display the notification
197218
notification_id = random.randint(0, 100)
198219
notification_manager.notify(notification_id, builder.build())

docs/examples/flet-working/src/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def send_basic(e):
2929

3030
try:
3131
from core import send_notification
32-
send_notification(title='Hello World',message='From android_notify',custom_app_icon=f'assets/icon.png')
32+
send_notification(title='Hello World',message='From android_notify',custom_app_icon_path=f'assets/icon.png')
3333
except Exception as e:
3434
print("Error importing android_notify: {}".format(e))
3535

0 commit comments

Comments
 (0)