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