Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion android_notify/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ def send_notification(
notification_manager.createNotificationChannel(channel)

# Build the notification
builder = NotificationCompatBuilder(context, channel_id)
if BuildVersion.SDK_INT >= 26:
builder = NotificationCompatBuilder(context, channel_id)
else:
# Before Android 8.0 the platform Notification$Builder only has the
# (Context) constructor; the (Context, String channelId) overload
# requires API 26+. The androidx Builder accepts both forms on all APIs.
builder = NotificationCompatBuilder(context)
builder.setContentTitle(title)
builder.setContentText(message)
insert_app_icon(builder, custom_app_icon_path)
Expand Down
8 changes: 8 additions & 0 deletions android_notify/internal/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@
def check_notification_permission_legacy_android12_below():
# Below Android 13 there is no POST_NOTIFICATIONS runtime permission
# so check the per-app notification enabled state instead.
if BuildVersion.SDK_INT < 24:
# NotificationManager.areNotificationsEnabled() only exists on API 24+
# (before that there is no per-app notification toggle -> always on).
return True
context = get_python_activity_context()
notification_service = context.getSystemService(Context.NOTIFICATION_SERVICE)
return notification_service.areNotificationsEnabled()

def check_notification_permission_androidx_android12_below():
if BuildVersion.SDK_INT < 24:
# NotificationManagerCompat.areNotificationsEnabled() delegates to the
# platform API-24+ method; before that notifications are always enabled.
return True
context = get_python_activity_context()
func_from = getattr(NotificationManagerCompat, "from")
compat_manager = func_from(context)
Expand Down
8 changes: 7 additions & 1 deletion android_notify/sword.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ def __init__(self, **kwargs): # @dataclass already does work

self.notification_manager = get_notification_manager()
context = get_python_activity_context()
self.builder = NotificationCompatBuilder(context, self.channel_id)
if BuildVersion.SDK_INT >= 26:
self.builder = NotificationCompatBuilder(context, self.channel_id)
else:
# Before Android 8.0 the platform Notification$Builder only has the
# (Context) constructor; the (Context, String channelId) overload
# requires API 26+.
self.builder = NotificationCompatBuilder(context)

def setData(self, data_object:dict):
"""
Expand Down