mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +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.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.annotation.AnyThread
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.annotation.WorkerThread
|
||||
|
|
@ -68,6 +69,7 @@ import org.linphone.core.tools.Log
|
|||
import org.linphone.ui.call.CallActivity
|
||||
import org.linphone.ui.main.MainActivity
|
||||
import org.linphone.utils.AppUtils
|
||||
import org.linphone.utils.FileUtils
|
||||
import org.linphone.utils.LinphoneUtils
|
||||
import org.linphone.utils.ShortcutUtils
|
||||
|
||||
|
|
@ -661,27 +663,22 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
)
|
||||
|
||||
for (content in message.contents) {
|
||||
/*if (content.isFile) { // TODO: show image in notif if possible
|
||||
if (content.isFile) {
|
||||
val path = content.filePath
|
||||
if (path != null) {
|
||||
val contentUri: Uri = FileUtils.getFilePath(context, path)
|
||||
val filePath: String = contentUri.toString()
|
||||
val contentUri = FileUtils.getPublicFilePath(context, path)
|
||||
val filePath = contentUri.toString()
|
||||
val extension = FileUtils.getExtensionFromFileName(filePath)
|
||||
if (extension.isNotEmpty()) {
|
||||
val mime =
|
||||
MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
|
||||
val mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
|
||||
notifiableMessage.filePath = contentUri
|
||||
notifiableMessage.fileMime = mime
|
||||
Log.i(
|
||||
"$TAG Added file $contentUri with MIME $mime to notification"
|
||||
)
|
||||
Log.i("$TAG Added file $contentUri with MIME $mime to notification")
|
||||
} else {
|
||||
Log.e(
|
||||
"$TAG Couldn't find extension for incoming message with file $path"
|
||||
)
|
||||
Log.e("$TAG Couldn't find extension for incoming message with file $path")
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
return notifiableMessage
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import android.system.Os
|
|||
import android.text.format.Formatter
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.annotation.AnyThread
|
||||
import androidx.core.content.FileProvider
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
|
|
@ -38,6 +39,7 @@ import java.util.Locale
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.R
|
||||
import org.linphone.core.tools.Log
|
||||
|
||||
class FileUtils {
|
||||
|
|
@ -155,6 +157,41 @@ class FileUtils {
|
|||
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? {
|
||||
return withContext(Dispatchers.IO) {
|
||||
val name: String = getNameFromUri(uri, context)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue