Adding contentIntent to file transfer & push notification services

This commit is contained in:
Sylvain Berfini 2024-08-29 11:16:15 +02:00
parent bed9288f21
commit 5d7addb8d8
2 changed files with 30 additions and 1 deletions

View file

@ -20,6 +20,7 @@
package org.linphone.core
import android.Manifest
import android.app.PendingIntent
import android.content.Intent
import android.content.pm.PackageManager
import android.os.IBinder
@ -33,6 +34,7 @@ import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R
import org.linphone.core.tools.Log
import org.linphone.core.tools.service.FileTransferService
import org.linphone.ui.main.MainActivity
@MainThread
class CoreFileTransferService : FileTransferService() {
@ -80,6 +82,17 @@ class CoreFileTransferService : FileTransferService() {
}
override fun createServiceNotification() {
Log.i("$TAG Creating notification")
val intent = Intent(applicationContext, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
val pendingIntent = PendingIntent.getActivity(
applicationContext,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
mServiceNotification = builder.setContentTitle(
getString(R.string.notification_file_transfer_title)
)
@ -92,6 +105,7 @@ class CoreFileTransferService : FileTransferService() {
.setShowWhen(false)
.setOngoing(true)
.setProgress(0, 0, true)
.setContentIntent(pendingIntent)
.build()
postNotification()
@ -130,7 +144,7 @@ class CoreFileTransferService : FileTransferService() {
} else if (uploadingFilesCount > 0) {
uploadText
} else {
getString(R.string.notification_file_transfer_title)
getString(R.string.notification_file_transfer_startup_message)
}
mServiceNotification = builder.setContentText(message).build()
@ -146,6 +160,7 @@ class CoreFileTransferService : FileTransferService() {
) == PackageManager.PERMISSION_GRANTED
) {
if (mServiceNotification != null) {
Log.i("$TAG Sending notification to manager")
notificationsManager.notify(SERVICE_NOTIF_ID, mServiceNotification)
} else {
Log.e("$TAG Notification content hasn't been computed yet!")

View file

@ -19,6 +19,7 @@
*/
package org.linphone.core
import android.app.PendingIntent
import android.content.Intent
import android.os.IBinder
import androidx.annotation.MainThread
@ -26,6 +27,7 @@ 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.ui.main.MainActivity
@MainThread
class CorePushService : PushService() {
@ -58,6 +60,17 @@ class CorePushService : PushService() {
}
override fun createServiceNotification() {
Log.i("$TAG Creating notification")
val intent = Intent(applicationContext, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
val pendingIntent = PendingIntent.getActivity(
applicationContext,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
mServiceNotification = NotificationCompat.Builder(
this,
SERVICE_NOTIFICATION_CHANNEL_ID
@ -71,6 +84,7 @@ class CorePushService : PushService() {
.setWhen(System.currentTimeMillis())
.setShowWhen(false)
.setOngoing(true)
.setContentIntent(pendingIntent)
.build()
}
}