Fixed image not showed in notification when auto download is enabled
This commit is contained in:
parent
b6934e02fd
commit
7fdc49baa1
4 changed files with 62 additions and 39 deletions
|
@ -22,7 +22,6 @@ package org.linphone.activities.call
|
|||
import android.annotation.TargetApi
|
||||
import android.app.KeyguardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.WindowManager
|
||||
import androidx.databinding.DataBindingUtil
|
||||
|
|
|
@ -32,7 +32,6 @@ import android.view.*
|
|||
import android.webkit.MimeTypeMap
|
||||
import androidx.appcompat.view.menu.MenuBuilder
|
||||
import androidx.appcompat.view.menu.MenuPopupHelper
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
|
@ -40,7 +39,6 @@ import androidx.navigation.Navigation
|
|||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import java.io.File
|
||||
import kotlinx.android.synthetic.main.tabs_fragment.*
|
||||
import kotlinx.coroutines.launch
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
|
@ -520,39 +518,8 @@ class DetailChatRoomFragment : MasterFragment() {
|
|||
|
||||
private fun openFile(contentFilePath: String) {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
val contentUri: Uri
|
||||
var path = contentFilePath
|
||||
|
||||
when {
|
||||
path.startsWith("file://") -> {
|
||||
path = path.substring("file://".length)
|
||||
val file = File(path)
|
||||
contentUri = FileProvider.getUriForFile(
|
||||
requireContext(),
|
||||
getString(R.string.file_provider),
|
||||
file
|
||||
)
|
||||
}
|
||||
path.startsWith("content://") -> {
|
||||
contentUri = Uri.parse(path)
|
||||
}
|
||||
else -> {
|
||||
val file = File(path)
|
||||
contentUri = try {
|
||||
FileProvider.getUriForFile(
|
||||
requireContext(),
|
||||
getString(R.string.file_provider),
|
||||
file
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
Log.e(
|
||||
"[Chat Message] Couldn't get URI for file $file using file provider ${getString(R.string.file_provider)}"
|
||||
)
|
||||
Uri.parse(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val contentUri: Uri = FileUtils.getPublicFilePath(requireContext(), path)
|
||||
val filePath: String = contentUri.toString()
|
||||
Log.i("[Chat Message] Trying to open file: $filePath")
|
||||
var type: String? = null
|
||||
|
|
|
@ -26,6 +26,7 @@ import android.content.Intent
|
|||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.webkit.MimeTypeMap
|
||||
import android.widget.RemoteViews
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
|
@ -45,6 +46,7 @@ import org.linphone.compatibility.Compatibility
|
|||
import org.linphone.contact.Contact
|
||||
import org.linphone.core.*
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.FileUtils
|
||||
import org.linphone.utils.ImageUtils
|
||||
import org.linphone.utils.LinphoneUtils
|
||||
|
||||
|
@ -128,8 +130,8 @@ class NotificationsManager(private val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onMessageReceived(core: Core?, room: ChatRoom?, message: ChatMessage?) {
|
||||
if (message == null || room == null || message.isOutgoing) return
|
||||
override fun onMessageReceived(core: Core, room: ChatRoom, message: ChatMessage) {
|
||||
if (message.isOutgoing) return
|
||||
|
||||
if (currentlyDisplayedChatRoomAddress == room.peerAddress?.asStringUriOnly()) {
|
||||
Log.i("[Notifications Manager] Chat room is currently displayed, do not notify received message")
|
||||
|
@ -151,8 +153,8 @@ class NotificationsManager(private val context: Context) {
|
|||
}
|
||||
|
||||
val chatListener: ChatMessageListener = object : ChatMessageListenerStub() {
|
||||
override fun onMsgStateChanged(message: ChatMessage?, state: ChatMessage.State?) {
|
||||
if (message == null || message.userData == null) return
|
||||
override fun onMsgStateChanged(message: ChatMessage, state: ChatMessage.State) {
|
||||
message.userData ?: return
|
||||
val id = message.userData as Int
|
||||
Log.i("[Notifications Manager] Reply message state changed [$state] for id $id")
|
||||
|
||||
|
@ -543,6 +545,25 @@ class NotificationsManager(private val context: Context) {
|
|||
val notifiableMessage = NotifiableMessage(text, contact, displayName, message.time, senderAvatar = roundPicture)
|
||||
notifiable.messages.add(notifiableMessage)
|
||||
|
||||
for (content in message.contents) {
|
||||
if (content.isFile) {
|
||||
val path = content.filePath
|
||||
if (path != null) {
|
||||
val contentUri: Uri = FileUtils.getPublicFilePath(context, path)
|
||||
val filePath: String = contentUri.toString()
|
||||
val extension = FileUtils.getExtensionFromFileName(filePath)
|
||||
if (extension.isNotEmpty()) {
|
||||
val mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
|
||||
notifiableMessage.filePath = contentUri
|
||||
notifiableMessage.fileMime = mime
|
||||
Log.i("[Notifications Manager] Added file $contentUri with MIME $mime to notification")
|
||||
} else {
|
||||
Log.e("[Notifications Manager] Couldn't find extension for incoming message with file $path")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (room.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
|
||||
notifiable.isGroup = false
|
||||
} else {
|
||||
|
|
|
@ -23,6 +23,7 @@ import android.content.Context
|
|||
import android.net.Uri
|
||||
import android.os.Environment
|
||||
import android.provider.OpenableColumns
|
||||
import androidx.core.content.FileProvider
|
||||
import java.io.*
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
@ -31,6 +32,7 @@ import kotlinx.coroutines.async
|
|||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.R
|
||||
import org.linphone.core.tools.Log
|
||||
|
||||
class FileUtils {
|
||||
|
@ -230,5 +232,39 @@ class FileUtils {
|
|||
SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date())
|
||||
}
|
||||
}
|
||||
|
||||
fun getPublicFilePath(context: Context, path: String): Uri {
|
||||
var contentUri: Uri
|
||||
when {
|
||||
path.startsWith("file://") -> {
|
||||
val file = File(path.substring("file://".length))
|
||||
contentUri = FileProvider.getUriForFile(
|
||||
context,
|
||||
context.getString(R.string.file_provider),
|
||||
file
|
||||
)
|
||||
}
|
||||
path.startsWith("content://") -> {
|
||||
contentUri = Uri.parse(path)
|
||||
}
|
||||
else -> {
|
||||
val file = File(path)
|
||||
contentUri = try {
|
||||
FileProvider.getUriForFile(
|
||||
context,
|
||||
context.getString(R.string.file_provider),
|
||||
file
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
Log.e(
|
||||
"[Chat Message] Couldn't get URI for file $file using file provider ${context.getString(
|
||||
R.string.file_provider)}"
|
||||
)
|
||||
Uri.parse(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
return contentUri
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue