mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-05-15 20:27:55 +00:00
Added auto downloaded files to notifications
This commit is contained in:
parent
370b786ed0
commit
2f18ecb562
2 changed files with 46 additions and 12 deletions
|
|
@ -32,6 +32,7 @@ import android.content.pm.ServiceInfo
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.webkit.MimeTypeMap
|
||||||
import androidx.annotation.AnyThread
|
import androidx.annotation.AnyThread
|
||||||
import androidx.annotation.MainThread
|
import androidx.annotation.MainThread
|
||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
|
|
@ -68,6 +69,7 @@ import org.linphone.core.tools.Log
|
||||||
import org.linphone.ui.call.CallActivity
|
import org.linphone.ui.call.CallActivity
|
||||||
import org.linphone.ui.main.MainActivity
|
import org.linphone.ui.main.MainActivity
|
||||||
import org.linphone.utils.AppUtils
|
import org.linphone.utils.AppUtils
|
||||||
|
import org.linphone.utils.FileUtils
|
||||||
import org.linphone.utils.LinphoneUtils
|
import org.linphone.utils.LinphoneUtils
|
||||||
import org.linphone.utils.ShortcutUtils
|
import org.linphone.utils.ShortcutUtils
|
||||||
|
|
||||||
|
|
@ -661,27 +663,22 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
||||||
)
|
)
|
||||||
|
|
||||||
for (content in message.contents) {
|
for (content in message.contents) {
|
||||||
/*if (content.isFile) { // TODO: show image in notif if possible
|
if (content.isFile) {
|
||||||
val path = content.filePath
|
val path = content.filePath
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
val contentUri: Uri = FileUtils.getFilePath(context, path)
|
val contentUri = FileUtils.getPublicFilePath(context, path)
|
||||||
val filePath: String = contentUri.toString()
|
val filePath = contentUri.toString()
|
||||||
val extension = FileUtils.getExtensionFromFileName(filePath)
|
val extension = FileUtils.getExtensionFromFileName(filePath)
|
||||||
if (extension.isNotEmpty()) {
|
if (extension.isNotEmpty()) {
|
||||||
val mime =
|
val mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
|
||||||
MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
|
|
||||||
notifiableMessage.filePath = contentUri
|
notifiableMessage.filePath = contentUri
|
||||||
notifiableMessage.fileMime = mime
|
notifiableMessage.fileMime = mime
|
||||||
Log.i(
|
Log.i("$TAG Added file $contentUri with MIME $mime to notification")
|
||||||
"$TAG Added file $contentUri with MIME $mime to notification"
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
Log.e(
|
Log.e("$TAG Couldn't find extension for incoming message with file $path")
|
||||||
"$TAG Couldn't find extension for incoming message with file $path"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return notifiableMessage
|
return notifiableMessage
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import android.system.Os
|
||||||
import android.text.format.Formatter
|
import android.text.format.Formatter
|
||||||
import android.webkit.MimeTypeMap
|
import android.webkit.MimeTypeMap
|
||||||
import androidx.annotation.AnyThread
|
import androidx.annotation.AnyThread
|
||||||
|
import androidx.core.content.FileProvider
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
|
|
@ -38,6 +39,7 @@ import java.util.Locale
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
|
import org.linphone.R
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
|
|
||||||
class FileUtils {
|
class FileUtils {
|
||||||
|
|
@ -155,6 +157,41 @@ class FileUtils {
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getPublicFilePath(context: Context, path: String): Uri {
|
||||||
|
val 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(
|
||||||
|
"$TAG Couldn't get URI for file $file using file provider ${context.getString(
|
||||||
|
R.string.file_provider
|
||||||
|
)}"
|
||||||
|
)
|
||||||
|
Uri.parse(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return contentUri
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun getFilePath(context: Context, uri: Uri, overrideExisting: Boolean): String? {
|
suspend fun getFilePath(context: Context, uri: Uri, overrideExisting: Boolean): String? {
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
val name: String = getNameFromUri(uri, context)
|
val name: String = getNameFromUri(uri, context)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue