From 1e604f15a86e122bbd6e6625c973b39b636eed38 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 22 Sep 2024 00:36:35 +0200 Subject: [PATCH] Open conversations from notifications on Android --- sbapp/main.py | 14 ++++++++------ sbapp/services/sidebandservice.py | 16 ++++++++-------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/sbapp/main.py b/sbapp/main.py index 4bda02d..f428539 100644 --- a/sbapp/main.py +++ b/sbapp/main.py @@ -830,12 +830,14 @@ class SidebandApp(MDApp): JString = autoclass('java.lang.String') Intent = autoclass("android.content.Intent") try: - data = intent.getExtras().getString("intent_action", "undefined") - if data.startswith("conversation."): - conv_hexhash = bytes.fromhex(data.replace("conversation.", "")) - def cb(dt): - self.open_conversation(conv_hexhash) - Clock.schedule_once(cb, 0.2) + extras = intent.getExtras() + if extras: + data = extras.getString("intent_action", "undefined") + if data.startswith("conversation."): + conv_hexhash = bytes.fromhex(data.replace("conversation.", "")) + def cb(dt): + self.open_conversation(conv_hexhash) + Clock.schedule_once(cb, 0.2) except Exception as e: RNS.log(f"Error while getting intent action data: {e}", RNS.LOG_ERROR) diff --git a/sbapp/services/sidebandservice.py b/sbapp/services/sidebandservice.py index 8864662..b263e65 100644 --- a/sbapp/services/sidebandservice.py +++ b/sbapp/services/sidebandservice.py @@ -116,14 +116,14 @@ class SidebandService(): # 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) - if context_id != None: - notification_intent.putExtra(JString("intent_action"), JString(f"conversation.{context_id}")) - self.notification_intent = PendingIntent.getActivity(self.app_context, 0, notification_intent, PendingIntent.FLAG_MUTABLE) + 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) + if context_id != None: + cstr = f"conversation.{context_id}" + notification_intent.putExtra(JString("intent_action"), JString(cstr)) + self.notification_intent = PendingIntent.getActivity(self.app_context, 0, notification_intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT) notification.setContentIntent(self.notification_intent) notification.setAutoCancel(True)