From 9c3102392b5a18c3ca801bfa36a6b797d9158d40 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 19 Feb 2024 12:10:22 +0100 Subject: [PATCH] Improved push notification received notification by inheriting PushService from SDK --- app/src/main/AndroidManifest.xml | 2 +- .../java/org/linphone/core/CorePushService.kt | 77 +++++++++++++++++++ .../res/drawable/linphone_notification.xml | 15 ++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/org/linphone/core/CorePushService.kt create mode 100644 app/src/main/res/drawable/linphone_notification.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 87b6d38bc..74a60260f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -135,7 +135,7 @@ android:label="@string/app_name" /> . + */ +package org.linphone.core + +import android.content.Intent +import android.os.IBinder +import androidx.annotation.MainThread +import androidx.core.app.NotificationCompat +import org.linphone.R +import org.linphone.core.tools.Log +import org.linphone.core.tools.service.PushService +import org.linphone.notifications.NotificationsManager + +@MainThread +class CorePushService : PushService() { + companion object { + private const val TAG = "[Core Push Service]" + } + + override fun onCreate() { + super.onCreate() + Log.i("$TAG Created") + } + + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + Log.i("$TAG onStartCommand") + return super.onStartCommand(intent, flags, startId) + } + + override fun onTaskRemoved(rootIntent: Intent?) { + Log.i("$TAG Task removed, doing nothing") + super.onTaskRemoved(rootIntent) + } + + override fun onDestroy() { + Log.i("$TAG onDestroy") + super.onDestroy() + } + + override fun onBind(p0: Intent?): IBinder? { + return null + } + + override fun createServiceNotification() { + mServiceNotification = NotificationCompat.Builder( + this, + SERVICE_NOTIFICATION_CHANNEL_ID + ) + .setContentTitle(getString(R.string.notification_push_received_title)) + .setSmallIcon(R.drawable.linphone_notification) + .setAutoCancel(false) + .setCategory(NotificationCompat.CATEGORY_SERVICE) + .setGroup(NotificationsManager.CHAT_NOTIFICATIONS_GROUP) + .setVisibility(NotificationCompat.VISIBILITY_SECRET) + .setWhen(System.currentTimeMillis()) + .setShowWhen(true) + .setOngoing(true) + .build() + } +} diff --git a/app/src/main/res/drawable/linphone_notification.xml b/app/src/main/res/drawable/linphone_notification.xml new file mode 100644 index 000000000..a7858cb4e --- /dev/null +++ b/app/src/main/res/drawable/linphone_notification.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5d374ec43..6e0fccf67 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -67,6 +67,7 @@ Missed call from %s %s missed calls Missed call + Push notification received Welcome in Linphone