Open conversations from notifications on Android

This commit is contained in:
Mark Qvist 2024-09-22 00:36:35 +02:00
parent 30ccd64535
commit 1e604f15a8
2 changed files with 16 additions and 14 deletions

View File

@ -830,12 +830,14 @@ class SidebandApp(MDApp):
JString = autoclass('java.lang.String') JString = autoclass('java.lang.String')
Intent = autoclass("android.content.Intent") Intent = autoclass("android.content.Intent")
try: try:
data = intent.getExtras().getString("intent_action", "undefined") extras = intent.getExtras()
if data.startswith("conversation."): if extras:
conv_hexhash = bytes.fromhex(data.replace("conversation.", "")) data = extras.getString("intent_action", "undefined")
def cb(dt): if data.startswith("conversation."):
self.open_conversation(conv_hexhash) conv_hexhash = bytes.fromhex(data.replace("conversation.", ""))
Clock.schedule_once(cb, 0.2) def cb(dt):
self.open_conversation(conv_hexhash)
Clock.schedule_once(cb, 0.2)
except Exception as e: except Exception as e:
RNS.log(f"Error while getting intent action data: {e}", RNS.LOG_ERROR) RNS.log(f"Error while getting intent action data: {e}", RNS.LOG_ERROR)

View File

@ -116,14 +116,14 @@ class SidebandService():
# bitmap_icon = BitmapFactory.decodeFile(large_icon_path) # bitmap_icon = BitmapFactory.decodeFile(large_icon_path)
# notification.setLargeIcon(bitmap_icon) # notification.setLargeIcon(bitmap_icon)
if not self.notification_intent: notification_intent = Intent(self.app_context, python_act)
notification_intent = Intent(self.app_context, python_act) notification_intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
notification_intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) notification_intent.setAction(Intent.ACTION_MAIN)
notification_intent.setAction(Intent.ACTION_MAIN) notification_intent.addCategory(Intent.CATEGORY_LAUNCHER)
notification_intent.addCategory(Intent.CATEGORY_LAUNCHER) if context_id != None:
if context_id != None: cstr = f"conversation.{context_id}"
notification_intent.putExtra(JString("intent_action"), JString(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_MUTABLE) self.notification_intent = PendingIntent.getActivity(self.app_context, 0, notification_intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT)
notification.setContentIntent(self.notification_intent) notification.setContentIntent(self.notification_intent)
notification.setAutoCancel(True) notification.setAutoCancel(True)