mirror of
https://github.com/liberatedsystems/openCom-Companion.git
synced 2024-11-25 23:00:36 +01:00
Improved notification handling on Android
This commit is contained in:
parent
4a12c136a0
commit
30ccd64535
@ -820,11 +820,27 @@ class SidebandApp(MDApp):
|
|||||||
self.check_bluetooth_permissions()
|
self.check_bluetooth_permissions()
|
||||||
|
|
||||||
def on_new_intent(self, intent):
|
def on_new_intent(self, intent):
|
||||||
RNS.log("Received intent", RNS.LOG_DEBUG)
|
|
||||||
intent_action = intent.getAction()
|
intent_action = intent.getAction()
|
||||||
action = None
|
action = None
|
||||||
data = None
|
data = None
|
||||||
|
|
||||||
|
RNS.log(f"Received intent: {intent_action}", RNS.LOG_DEBUG)
|
||||||
|
|
||||||
|
if intent_action == "android.intent.action.MAIN":
|
||||||
|
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)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log(f"Error while getting intent action data: {e}", RNS.LOG_ERROR)
|
||||||
|
RNS.trace_exception(e)
|
||||||
|
|
||||||
if intent_action == "android.intent.action.WEB_SEARCH":
|
if intent_action == "android.intent.action.WEB_SEARCH":
|
||||||
SearchManager = autoclass('android.app.SearchManager')
|
SearchManager = autoclass('android.app.SearchManager')
|
||||||
data = intent.getStringExtra(SearchManager.QUERY)
|
data = intent.getStringExtra(SearchManager.QUERY)
|
||||||
|
@ -142,13 +142,13 @@ public class PythonService extends Service implements Runnable {
|
|||||||
manager.createNotificationChannel(chan);
|
manager.createNotificationChannel(chan);
|
||||||
|
|
||||||
Notification.Builder builder = new Notification.Builder(context, NOTIFICATION_CHANNEL_ID);
|
Notification.Builder builder = new Notification.Builder(context, NOTIFICATION_CHANNEL_ID);
|
||||||
builder.setContentTitle("Sideband Active");
|
builder.setContentTitle("Reticulum available");
|
||||||
// builder.setContentText("Reticulum Active");
|
// builder.setContentText("Reticulum available");
|
||||||
builder.setContentIntent(pIntent);
|
builder.setContentIntent(pIntent);
|
||||||
// builder.setOngoing(true);
|
// builder.setOngoing(true);
|
||||||
|
|
||||||
String files_path = context.getFilesDir().getPath();
|
String files_path = context.getFilesDir().getPath();
|
||||||
Bitmap icon_bitmap = BitmapFactory.decodeFile(files_path+"/app/assets/notification_icon.png");
|
Bitmap icon_bitmap = BitmapFactory.decodeFile(files_path+"/app/assets/notification_icon_black.png");
|
||||||
Icon service_icon = Icon.createWithBitmap(icon_bitmap);
|
Icon service_icon = Icon.createWithBitmap(icon_bitmap);
|
||||||
// builder.setSmallIcon(context.getApplicationInfo().icon);
|
// builder.setSmallIcon(context.getApplicationInfo().icon);
|
||||||
builder.setSmallIcon(service_icon);
|
builder.setSmallIcon(service_icon);
|
||||||
|
@ -38,6 +38,7 @@ 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')
|
||||||
|
JString = autoclass('java.lang.String')
|
||||||
|
|
||||||
if android_api_version >= 26:
|
if android_api_version >= 26:
|
||||||
NotificationBuilder = autoclass('android.app.Notification$Builder')
|
NotificationBuilder = autoclass('android.app.Notification$Builder')
|
||||||
@ -90,22 +91,26 @@ class SidebandService():
|
|||||||
|
|
||||||
self.notification_channel = NotificationChannel(channel_id, channel_name, NotificationManager.IMPORTANCE_DEFAULT)
|
self.notification_channel = NotificationChannel(channel_id, channel_name, NotificationManager.IMPORTANCE_DEFAULT)
|
||||||
self.notification_channel.enableVibration(True)
|
self.notification_channel.enableVibration(True)
|
||||||
|
self.notification_channel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), None)
|
||||||
self.notification_channel.setShowBadge(True)
|
self.notification_channel.setShowBadge(True)
|
||||||
self.notification_service.createNotificationChannel(self.notification_channel)
|
self.notification_service.createNotificationChannel(self.notification_channel)
|
||||||
|
|
||||||
notification = NotificationBuilder(self.app_context, channel_id)
|
notification = NotificationBuilder(self.app_context, channel_id)
|
||||||
notification.setContentTitle(title)
|
notification.setContentTitle(title)
|
||||||
notification.setContentText(AndroidString(content))
|
notification.setContentText(AndroidString(content))
|
||||||
|
notification.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
|
||||||
|
|
||||||
# if group != None:
|
# if group != None:
|
||||||
# notification.setGroup(group_id)
|
# notification.setGroup(group_id)
|
||||||
|
|
||||||
if not self.notification_small_icon:
|
if not self.notification_small_icon:
|
||||||
path = self.sideband.notification_icon
|
# path = self.sideband.notification_icon
|
||||||
|
path = self.sideband.notif_icon_black
|
||||||
bitmap = BitmapFactory.decodeFile(path)
|
bitmap = BitmapFactory.decodeFile(path)
|
||||||
self.notification_small_icon = Icon.createWithBitmap(bitmap)
|
self.notification_small_icon = Icon.createWithBitmap(bitmap)
|
||||||
|
|
||||||
notification.setSmallIcon(self.notification_small_icon)
|
notification.setSmallIcon(self.notification_small_icon)
|
||||||
|
# notification.setLargeIcon(self.notification_small_icon)
|
||||||
|
|
||||||
# large_icon_path = self.sideband.icon
|
# large_icon_path = self.sideband.icon
|
||||||
# bitmap_icon = BitmapFactory.decodeFile(large_icon_path)
|
# bitmap_icon = BitmapFactory.decodeFile(large_icon_path)
|
||||||
@ -116,7 +121,9 @@ class SidebandService():
|
|||||||
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)
|
||||||
self.notification_intent = PendingIntent.getActivity(self.app_context, 0, notification_intent, PendingIntent.FLAG_IMMUTABLE)
|
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.setContentIntent(self.notification_intent)
|
notification.setContentIntent(self.notification_intent)
|
||||||
notification.setAutoCancel(True)
|
notification.setAutoCancel(True)
|
||||||
|
@ -198,6 +198,7 @@ class SidebandCore():
|
|||||||
self.icon_32 = self.asset_dir+"/icon_32.png"
|
self.icon_32 = self.asset_dir+"/icon_32.png"
|
||||||
self.icon_macos = self.asset_dir+"/icon_macos.png"
|
self.icon_macos = self.asset_dir+"/icon_macos.png"
|
||||||
self.notification_icon = self.asset_dir+"/notification_icon.png"
|
self.notification_icon = self.asset_dir+"/notification_icon.png"
|
||||||
|
self.notif_icon_black = self.asset_dir+"/notification_icon_black.png"
|
||||||
|
|
||||||
os.environ["TELEMETER_GEOID_PATH"] = os.path.join(self.asset_dir, "geoids")
|
os.environ["TELEMETER_GEOID_PATH"] = os.path.join(self.asset_dir, "geoids")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user