mirror of
https://github.com/liberatedsystems/Sideband_CE.git
synced 2024-09-03 04:13:27 +02:00
Disable notifications on Android API levels less than 26
This commit is contained in:
parent
c3ac63db6d
commit
41774a5629
@ -55,6 +55,7 @@ if RNS.vendor.platformutils.get_platform() == "android":
|
|||||||
from android.permissions import request_permissions, check_permission
|
from android.permissions import request_permissions, check_permission
|
||||||
|
|
||||||
from kivymd.utils.set_bars_colors import set_bars_colors
|
from kivymd.utils.set_bars_colors import set_bars_colors
|
||||||
|
android_api_version = autoclass('android.os.Build$VERSION').SDK_INT
|
||||||
|
|
||||||
else:
|
else:
|
||||||
from .sideband.core import SidebandCore
|
from .sideband.core import SidebandCore
|
||||||
@ -151,6 +152,9 @@ class SidebandApp(MDApp):
|
|||||||
self.sideband.setstate("app.foreground", True)
|
self.sideband.setstate("app.foreground", True)
|
||||||
|
|
||||||
def start_service(self):
|
def start_service(self):
|
||||||
|
if RNS.vendor.platformutils.is_android():
|
||||||
|
RNS.log("Running on Android API level "+str(android_api_version))
|
||||||
|
|
||||||
RNS.log("Launching platform-specific service for RNS and LXMF")
|
RNS.log("Launching platform-specific service for RNS and LXMF")
|
||||||
if RNS.vendor.platformutils.get_platform() == "android":
|
if RNS.vendor.platformutils.get_platform() == "android":
|
||||||
self.android_service = autoclass('io.unsigned.sideband.ServiceSidebandservice')
|
self.android_service = autoclass('io.unsigned.sideband.ServiceSidebandservice')
|
||||||
@ -217,10 +221,8 @@ class SidebandApp(MDApp):
|
|||||||
|
|
||||||
self.update_ui_colors()
|
self.update_ui_colors()
|
||||||
|
|
||||||
st = time.time()
|
# for wid in self.root.ids:
|
||||||
RNS.log("Recursing widgets...")
|
# RNS.log("Found: "+str(wid)+str(self.root.ids[wid]))
|
||||||
for wid in self.root.ids:
|
|
||||||
RNS.log("Found: "+str(wid)+str(self.root.ids[wid]))
|
|
||||||
|
|
||||||
def set_bars_colors(self):
|
def set_bars_colors(self):
|
||||||
if RNS.vendor.platformutils.get_platform() == "android":
|
if RNS.vendor.platformutils.get_platform() == "android":
|
||||||
@ -868,13 +870,13 @@ class SidebandApp(MDApp):
|
|||||||
### Settings screen
|
### Settings screen
|
||||||
######################################
|
######################################
|
||||||
def settings_action(self, sender=None):
|
def settings_action(self, sender=None):
|
||||||
self.root.ids.screen_manager.transition.direction = "left"
|
|
||||||
|
|
||||||
self.settings_init()
|
|
||||||
|
|
||||||
self.root.ids.screen_manager.current = "settings_screen"
|
|
||||||
self.root.ids.nav_drawer.set_state("closed")
|
self.root.ids.nav_drawer.set_state("closed")
|
||||||
self.sideband.setstate("app.displaying", self.root.ids.screen_manager.current)
|
def cb(dt):
|
||||||
|
self.root.ids.screen_manager.transition.direction = "left"
|
||||||
|
self.settings_init()
|
||||||
|
self.root.ids.screen_manager.current = "settings_screen"
|
||||||
|
self.sideband.setstate("app.displaying", self.root.ids.screen_manager.current)
|
||||||
|
Clock.schedule_once(cb, 0.2)
|
||||||
|
|
||||||
def settings_init(self, sender=None):
|
def settings_init(self, sender=None):
|
||||||
if not self.settings_ready:
|
if not self.settings_ready:
|
||||||
@ -969,8 +971,12 @@ class SidebandApp(MDApp):
|
|||||||
self.root.ids.settings_propagation_node_address.bind(on_text_validate=save_prop_addr)
|
self.root.ids.settings_propagation_node_address.bind(on_text_validate=save_prop_addr)
|
||||||
self.root.ids.settings_propagation_node_address.bind(focus=save_prop_addr)
|
self.root.ids.settings_propagation_node_address.bind(focus=save_prop_addr)
|
||||||
|
|
||||||
self.root.ids.settings_notifications_on.active = self.sideband.config["notifications_on"]
|
if android_api_version >= 26:
|
||||||
self.root.ids.settings_notifications_on.bind(active=save_notifications_on)
|
self.root.ids.settings_notifications_on.active = self.sideband.config["notifications_on"]
|
||||||
|
self.root.ids.settings_notifications_on.bind(active=save_notifications_on)
|
||||||
|
else:
|
||||||
|
self.root.ids.settings_notifications_on.active = False
|
||||||
|
self.root.ids.settings_notifications_on.disabled = True
|
||||||
|
|
||||||
self.root.ids.settings_dark_ui.active = self.sideband.config["dark_ui"]
|
self.root.ids.settings_dark_ui.active = self.sideband.config["dark_ui"]
|
||||||
self.root.ids.settings_dark_ui.bind(active=save_dark_ui)
|
self.root.ids.settings_dark_ui.bind(active=save_dark_ui)
|
||||||
|
@ -14,6 +14,8 @@ else:
|
|||||||
if RNS.vendor.platformutils.get_platform() == "android":
|
if RNS.vendor.platformutils.get_platform() == "android":
|
||||||
from jnius import autoclass, cast
|
from jnius import autoclass, cast
|
||||||
from android import python_act
|
from android import python_act
|
||||||
|
android_api_version = autoclass('android.os.Build$VERSION').SDK_INT
|
||||||
|
|
||||||
Context = autoclass('android.content.Context')
|
Context = autoclass('android.content.Context')
|
||||||
Intent = autoclass('android.content.Intent')
|
Intent = autoclass('android.content.Intent')
|
||||||
BitmapFactory = autoclass('android.graphics.BitmapFactory')
|
BitmapFactory = autoclass('android.graphics.BitmapFactory')
|
||||||
@ -22,9 +24,11 @@ if RNS.vendor.platformutils.get_platform() == "android":
|
|||||||
AndroidString = autoclass('java.lang.String')
|
AndroidString = autoclass('java.lang.String')
|
||||||
NotificationManager = autoclass('android.app.NotificationManager')
|
NotificationManager = autoclass('android.app.NotificationManager')
|
||||||
Context = autoclass('android.content.Context')
|
Context = autoclass('android.content.Context')
|
||||||
NotificationBuilder = autoclass('android.app.Notification$Builder')
|
|
||||||
NotificationChannel = autoclass('android.app.NotificationChannel')
|
if android_api_version >= 26:
|
||||||
|
NotificationBuilder = autoclass('android.app.Notification$Builder')
|
||||||
|
NotificationChannel = autoclass('android.app.NotificationChannel')
|
||||||
|
|
||||||
from usb4a import usb
|
from usb4a import usb
|
||||||
from usbserial4a import serial4a
|
from usbserial4a import serial4a
|
||||||
from sideband.core import SidebandCore
|
from sideband.core import SidebandCore
|
||||||
@ -34,62 +38,65 @@ else:
|
|||||||
|
|
||||||
class SidebandService():
|
class SidebandService():
|
||||||
def android_notification(self, title="", content="", ticker="", group=None, context_id=None):
|
def android_notification(self, title="", content="", ticker="", group=None, context_id=None):
|
||||||
package_name = "io.unsigned.sideband"
|
if android_api_version < 26:
|
||||||
|
return
|
||||||
if not self.notification_service:
|
|
||||||
self.notification_service = cast(NotificationManager, self.app_context.getSystemService(
|
|
||||||
Context.NOTIFICATION_SERVICE
|
|
||||||
))
|
|
||||||
|
|
||||||
channel_id = package_name
|
|
||||||
group_id = ""
|
|
||||||
if group != None:
|
|
||||||
channel_id += "."+str(group)
|
|
||||||
group_id += str(group)
|
|
||||||
if context_id != None:
|
|
||||||
channel_id += "."+str(context_id)
|
|
||||||
group_id += "."+str(context_id)
|
|
||||||
|
|
||||||
if not title or title == "":
|
|
||||||
channel_name = "Sideband"
|
|
||||||
else:
|
else:
|
||||||
channel_name = title
|
package_name = "io.unsigned.sideband"
|
||||||
|
|
||||||
self.notification_channel = NotificationChannel(channel_id, channel_name, NotificationManager.IMPORTANCE_DEFAULT)
|
if not self.notification_service:
|
||||||
self.notification_channel.enableVibration(True)
|
self.notification_service = cast(NotificationManager, self.app_context.getSystemService(
|
||||||
self.notification_channel.setShowBadge(True)
|
Context.NOTIFICATION_SERVICE
|
||||||
self.notification_service.createNotificationChannel(self.notification_channel)
|
))
|
||||||
|
|
||||||
notification = NotificationBuilder(self.app_context, channel_id)
|
channel_id = package_name
|
||||||
notification.setContentTitle(title)
|
group_id = ""
|
||||||
notification.setContentText(AndroidString(content))
|
if group != None:
|
||||||
|
channel_id += "."+str(group)
|
||||||
# if group != None:
|
group_id += str(group)
|
||||||
# notification.setGroup(group_id)
|
if context_id != None:
|
||||||
|
channel_id += "."+str(context_id)
|
||||||
|
group_id += "."+str(context_id)
|
||||||
|
|
||||||
if not self.notification_small_icon:
|
if not title or title == "":
|
||||||
path = self.sideband.notification_icon
|
channel_name = "Sideband"
|
||||||
bitmap = BitmapFactory.decodeFile(path)
|
else:
|
||||||
self.notification_small_icon = Icon.createWithBitmap(bitmap)
|
channel_name = title
|
||||||
|
|
||||||
notification.setSmallIcon(self.notification_small_icon)
|
self.notification_channel = NotificationChannel(channel_id, channel_name, NotificationManager.IMPORTANCE_DEFAULT)
|
||||||
|
self.notification_channel.enableVibration(True)
|
||||||
|
self.notification_channel.setShowBadge(True)
|
||||||
|
self.notification_service.createNotificationChannel(self.notification_channel)
|
||||||
|
|
||||||
# large_icon_path = self.sideband.icon
|
notification = NotificationBuilder(self.app_context, channel_id)
|
||||||
# bitmap_icon = BitmapFactory.decodeFile(large_icon_path)
|
notification.setContentTitle(title)
|
||||||
# notification.setLargeIcon(bitmap_icon)
|
notification.setContentText(AndroidString(content))
|
||||||
|
|
||||||
|
# if group != None:
|
||||||
|
# notification.setGroup(group_id)
|
||||||
|
|
||||||
if not self.notification_intent:
|
if not self.notification_small_icon:
|
||||||
notification_intent = Intent(self.app_context, python_act)
|
path = self.sideband.notification_icon
|
||||||
notification_intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
bitmap = BitmapFactory.decodeFile(path)
|
||||||
notification_intent.setAction(Intent.ACTION_MAIN)
|
self.notification_small_icon = Icon.createWithBitmap(bitmap)
|
||||||
notification_intent.addCategory(Intent.CATEGORY_LAUNCHER)
|
|
||||||
self.notification_intent = PendingIntent.getActivity(self.app_context, 0, notification_intent, 0)
|
|
||||||
|
|
||||||
notification.setContentIntent(self.notification_intent)
|
notification.setSmallIcon(self.notification_small_icon)
|
||||||
notification.setAutoCancel(True)
|
|
||||||
|
|
||||||
built_notification = notification.build()
|
# large_icon_path = self.sideband.icon
|
||||||
self.notification_service.notify(0, built_notification)
|
# bitmap_icon = BitmapFactory.decodeFile(large_icon_path)
|
||||||
|
# notification.setLargeIcon(bitmap_icon)
|
||||||
|
|
||||||
|
if not self.notification_intent:
|
||||||
|
notification_intent = Intent(self.app_context, python_act)
|
||||||
|
notification_intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||||
|
notification_intent.setAction(Intent.ACTION_MAIN)
|
||||||
|
notification_intent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
|
self.notification_intent = PendingIntent.getActivity(self.app_context, 0, notification_intent, 0)
|
||||||
|
|
||||||
|
notification.setContentIntent(self.notification_intent)
|
||||||
|
notification.setAutoCancel(True)
|
||||||
|
|
||||||
|
built_notification = notification.build()
|
||||||
|
self.notification_service.notify(0, built_notification)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.argument = environ.get('PYTHON_SERVICE_ARGUMENT', '')
|
self.argument = environ.get('PYTHON_SERVICE_ARGUMENT', '')
|
||||||
|
Loading…
Reference in New Issue
Block a user