Fixed issue when capturing image from camera from file picker intent
This commit is contained in:
parent
732e405c59
commit
7f2b3e9f5e
4 changed files with 72 additions and 60 deletions
|
@ -35,6 +35,7 @@ import android.webkit.MimeTypeMap
|
|||
import androidx.activity.addCallback
|
||||
import androidx.appcompat.view.menu.MenuBuilder
|
||||
import androidx.appcompat.view.menu.MenuPopupHelper
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
|
@ -343,13 +344,11 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
|||
data,
|
||||
chatSendingViewModel.temporaryFileUploadPath
|
||||
)) {
|
||||
if (fileToUploadPath != null) {
|
||||
chatSendingViewModel.addAttachment(fileToUploadPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun enterEditionMode() {
|
||||
listSelectionViewModel.isEditionEnabled.value = true
|
||||
|
@ -489,10 +488,16 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
|||
// Allows to capture directly from the camera
|
||||
val captureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
|
||||
val tempFileName = System.currentTimeMillis().toString() + ".jpeg"
|
||||
chatSendingViewModel.temporaryFileUploadPath =
|
||||
FileUtils.getFileStoragePath(tempFileName)
|
||||
val uri = Uri.fromFile(chatSendingViewModel.temporaryFileUploadPath)
|
||||
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri)
|
||||
val file = FileUtils.getFileStoragePath(tempFileName)
|
||||
chatSendingViewModel.temporaryFileUploadPath = file
|
||||
val publicUri = FileProvider.getUriForFile(
|
||||
requireContext(),
|
||||
requireContext().getString(R.string.file_provider),
|
||||
file
|
||||
)
|
||||
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, publicUri)
|
||||
captureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
captureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||
cameraIntents.add(captureIntent)
|
||||
}
|
||||
|
||||
|
|
|
@ -22,10 +22,10 @@ package org.linphone.activities.main.contact.fragments
|
|||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import android.provider.MediaStore
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
|
@ -162,9 +162,16 @@ class ContactEditorFragment : GenericFragment<ContactEditorFragmentBinding>(), S
|
|||
// Allows to capture directly from the camera
|
||||
val captureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
|
||||
val tempFileName = System.currentTimeMillis().toString() + ".jpeg"
|
||||
temporaryPicturePath = FileUtils.getFileStoragePath(tempFileName)
|
||||
val uri = Uri.fromFile(temporaryPicturePath)
|
||||
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri)
|
||||
val file = FileUtils.getFileStoragePath(tempFileName)
|
||||
temporaryPicturePath = file
|
||||
val publicUri = FileProvider.getUriForFile(
|
||||
requireContext(),
|
||||
requireContext().getString(R.string.file_provider),
|
||||
file
|
||||
)
|
||||
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, publicUri)
|
||||
captureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
captureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||
cameraIntents.add(captureIntent)
|
||||
}
|
||||
|
||||
|
|
|
@ -21,10 +21,10 @@ package org.linphone.activities.main.sidemenu.fragments
|
|||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import android.provider.MediaStore
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import java.io.File
|
||||
|
@ -139,9 +139,16 @@ class SideMenuFragment : GenericFragment<SideMenuFragmentBinding>() {
|
|||
// Allows to capture directly from the camera
|
||||
val captureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
|
||||
val tempFileName = System.currentTimeMillis().toString() + ".jpeg"
|
||||
temporaryPicturePath = FileUtils.getFileStoragePath(tempFileName)
|
||||
val uri = Uri.fromFile(temporaryPicturePath)
|
||||
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri)
|
||||
val file = FileUtils.getFileStoragePath(tempFileName)
|
||||
temporaryPicturePath = file
|
||||
val publicUri = FileProvider.getUriForFile(
|
||||
requireContext(),
|
||||
requireContext().getString(R.string.file_provider),
|
||||
file
|
||||
)
|
||||
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, publicUri)
|
||||
captureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
captureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||
cameraIntents.add(captureIntent)
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,6 @@ class ImageUtils {
|
|||
|
||||
suspend fun getFilesPathFromPickerIntent(data: Intent?, temporaryImageFilePath: File?): List<String> {
|
||||
var imageFilePath: String? = null
|
||||
if (temporaryImageFilePath != null) {
|
||||
if (data != null) {
|
||||
val clipData = data.clipData
|
||||
if (clipData != null) { // Multiple selection
|
||||
|
@ -94,48 +93,42 @@ class ImageUtils {
|
|||
if (dataUri != null) {
|
||||
imageFilePath = dataUri.toString()
|
||||
Log.i("[Image Utils] Using data URI $imageFilePath")
|
||||
} else if (temporaryImageFilePath.exists()) {
|
||||
} else if (temporaryImageFilePath?.exists() == true) {
|
||||
imageFilePath = temporaryImageFilePath.absolutePath
|
||||
Log.i("[Image Utils] Data URI is null, using $imageFilePath")
|
||||
}
|
||||
imageFilePath = cleanFilePath(imageFilePath)
|
||||
if (imageFilePath != null) return arrayListOf(imageFilePath)
|
||||
}
|
||||
} else if (temporaryImageFilePath.exists()) {
|
||||
} else if (temporaryImageFilePath?.exists() == true) {
|
||||
imageFilePath = temporaryImageFilePath.absolutePath
|
||||
Log.i("[Image Utils] Data is null, using $imageFilePath")
|
||||
imageFilePath = cleanFilePath(imageFilePath)
|
||||
if (imageFilePath != null) return arrayListOf(imageFilePath)
|
||||
}
|
||||
}
|
||||
return arrayListOf()
|
||||
}
|
||||
|
||||
suspend fun getFilePathFromPickerIntent(data: Intent?, temporaryImageFilePath: File?): String? {
|
||||
var imageFilePath: String? = null
|
||||
if (temporaryImageFilePath != null) {
|
||||
if (data != null) {
|
||||
val clipData = data.clipData
|
||||
if (clipData != null) { // Multiple selection
|
||||
for (i in 0 until clipData.itemCount) {
|
||||
val uri = clipData.getItemAt(i).uri
|
||||
}
|
||||
Log.e("[Image Utils] Expecting only one file, got ${clipData.itemCount}")
|
||||
} else { // Single selection
|
||||
val dataUri = data.data
|
||||
if (dataUri != null) {
|
||||
imageFilePath = dataUri.toString()
|
||||
Log.i("[Image Utils] Using data URI $imageFilePath")
|
||||
} else if (temporaryImageFilePath.exists()) {
|
||||
} else if (temporaryImageFilePath?.exists() == true) {
|
||||
imageFilePath = temporaryImageFilePath.absolutePath
|
||||
Log.i("[Image Utils] Data URI is null, using $imageFilePath")
|
||||
}
|
||||
}
|
||||
} else if (temporaryImageFilePath.exists()) {
|
||||
} else if (temporaryImageFilePath?.exists() == true) {
|
||||
imageFilePath = temporaryImageFilePath.absolutePath
|
||||
Log.i("[Image Utils] Data is null, using $imageFilePath")
|
||||
}
|
||||
}
|
||||
|
||||
return cleanFilePath(imageFilePath)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue