From a87e18f9509cd252509de2a2f66c1157c4630b2e Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 21 Apr 2021 13:22:07 +0200 Subject: [PATCH] Fixes issue on Android Q where the gif type was wrong --- .../handhistory/HandHistoryActivity.kt | 22 ++++++++++++++----- .../replayer/ReplayExportService.kt | 12 +++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt index 8c436f19..f02118e6 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt @@ -5,6 +5,7 @@ import android.content.ComponentName import android.content.Context import android.content.Intent import android.content.ServiceConnection +import android.os.Build import android.os.Bundle import android.os.IBinder import android.widget.Toast @@ -164,9 +165,13 @@ class HandHistoryActivity : BaseActivity() { Toast.makeText(this, R.string.video_export_started, Toast.LENGTH_LONG).show() - askForPermission(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), RequestCode.PERMISSION_WRITE_EXTERNAL_STORAGE.value) { granted -> - if (granted) { - gifExport() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + gifExport() + } else { + askForPermission(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), RequestCode.PERMISSION_WRITE_EXTERNAL_STORAGE.value) { granted -> + if (granted) { + gifExport() + } } } } @@ -175,11 +180,16 @@ class HandHistoryActivity : BaseActivity() { Toast.makeText(this, R.string.video_export_started, Toast.LENGTH_LONG).show() - askForPermission(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), RequestCode.PERMISSION_WRITE_EXTERNAL_STORAGE.value) { granted -> - if (granted) { - videoExport() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + videoExport() + } else { + askForPermission(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), RequestCode.PERMISSION_WRITE_EXTERNAL_STORAGE.value) { granted -> + if (granted) { + videoExport() + } } } + } private fun videoExport() { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayExportService.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayExportService.kt index 6fee8e1c..f9283b7e 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayExportService.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayExportService.kt @@ -31,8 +31,8 @@ import java.util.* import kotlin.coroutines.CoroutineContext enum class FileType(var value: String) { - IMAGE("image/gif"), - VIDEO("video/*") + IMAGE_GIF("image/gif"), + VIDEO_MP4("video/mp4") } class ReplayExportService : Service() { @@ -92,7 +92,7 @@ class ReplayExportService : Service() { animator.configure(width.toFloat(), height.toFloat(), context) val formattedDate = Date().dateTimeFileFormatted - val fileName = "hand_${formattedDate}.gif" + val fileName = "hand_${formattedDate}" // Add a specific media item. val resolver = applicationContext.contentResolver @@ -102,6 +102,7 @@ class ReplayExportService : Service() { val gifDetails = ContentValues().apply { put(MediaStore.Images.Media.DISPLAY_NAME, fileName) + put(MediaStore.Images.Media.MIME_TYPE, FileType.IMAGE_GIF.value) } val uri = resolver.insert(imageCollection, gifDetails) @@ -135,7 +136,7 @@ class ReplayExportService : Service() { writer.finishWrite(os) realm.close() - notifyUser(uri, FileType.IMAGE) + notifyUser(uri, FileType.IMAGE_GIF) } else { Timber.w("Resolver insert ended without uri...") } @@ -206,6 +207,7 @@ class ReplayExportService : Service() { val fileDetails = ContentValues().apply { Timber.d("set file details = $fileName") put(MediaStore.Video.Media.DISPLAY_NAME, fileName) + put(MediaStore.Images.Media.MIME_TYPE, FileType.VIDEO_MP4.value) } // copy video to nice path @@ -219,7 +221,7 @@ class ReplayExportService : Service() { file.delete() // delete temp file - notifyUser(uri, FileType.VIDEO) + notifyUser(uri, FileType.VIDEO_MP4) } ?: run { Timber.w("Resolver insert ended without uri...")