diff options
Diffstat (limited to 'modules/expo-receive-android-intents')
-rw-r--r-- | modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt b/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt index c88442057..abae882b4 100644 --- a/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt +++ b/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt @@ -2,6 +2,7 @@ package xyz.blueskyweb.app.exporeceiveandroidintents import android.content.Intent import android.graphics.Bitmap +import android.media.MediaMetadataRetriever import android.net.Uri import android.os.Build import android.provider.MediaStore @@ -143,7 +144,10 @@ class ExpoReceiveAndroidIntentsModule : Module() { appContext.currentActivity?.contentResolver?.openInputStream(uri)?.use { it.copyTo(out) } - "bluesky://intent/compose?videoUri=${URLEncoder.encode(file.path, "UTF-8")}".toUri().let { + + val info = getVideoInfo(uri) ?: return + + "bluesky://intent/compose?videoUri=${URLEncoder.encode(file.path, "UTF-8")}|${info["width"]}|${info["height"]}".toUri().let { val newIntent = Intent(Intent.ACTION_VIEW, it) appContext.currentActivity?.startActivity(newIntent) } @@ -166,6 +170,24 @@ class ExpoReceiveAndroidIntentsModule : Module() { ) } + private fun getVideoInfo(uri: Uri): Map<String, Any>? { + val retriever = MediaMetadataRetriever() + retriever.setDataSource(appContext.currentActivity, uri) + + val width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)?.toIntOrNull() + val height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)?.toIntOrNull() + + if (width == null || height == null) { + return null + } + + return mapOf( + "width" to width, + "height" to height, + "path" to uri.path.toString(), + ) + } + private fun createFile(extension: String): File = File.createTempFile(extension, "temp.$extension", appContext.currentActivity?.cacheDir) // We will pas the width and height to the app here, since getting measurements |