Skip to content

luisangeldd/Compose-Media-Picker

Repository files navigation

Compose-Media-Picker

Obtenga archivos de video/imagen de su dispositivo Android, alternativa al administrador de archivos predeterminado de Android.

License API GitHub release (latest by date) GitHub Repo stars GitHub all releases

Español   |    English

📱 Capturas


📱 Videos

video_preview.mp4
video_preview_change_languaje.mp4
video_preview_clean_content.mp4
video_preview_display_position_of_items_selected.mp4

📖 Características

  • Obtenga los archivos de video/imágenes de su dispositivo Android.

  • Un clic para seleccionar cualquier medio de su dispositivo.

  • Fácil de usar y amigable.

  • Inyeccion de dependencias manual, simple y rápido.

  • Interfaz de usuario de estilo Material Design 3.

  • Sólo Compose y Kotlin.

  • Inspirado en el selector de fotos de Android.

📖 Características Futuras

  • Mostrar carpetas del dispostivo y su contenido "Para algunos usuarios puede ser importante el poder acceder a carpetas especificas y buscar un contenido especifico".

  • Limitar la cantidad de items que es posible seleccionar "En algunos proyectos puede ser neesario el limitar la cantidad de archivos que es posible seleccionar ya sea por que seran enviados a algun repositorio y el espacio es importante".

⬇️ Cómo implemetar

Paso 1. Agregar las dependencias

dependencies {
    ...
    implementation 'com.github.luisangeldd:MediaPicker:Tag'
}
dependencies {
    ...
    implementation("com.github.luisangeldd:MediaPicker:Tag")
}

Paso 2. Configura tu archivo de manifiesto

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <!-- Required only if your app needs to access images or photos
    that other apps created. -->
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

    <!-- Required only if your app needs to access videos
         that other apps created. -->
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
        android:maxSdkVersion="32" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="32" />
    <application
        android:name=".App"
        ...
    </application>
</manifest>

Paso 3. Usar en tu aplicación

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            // request permissions
            val permissionsToRequest =
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                    arrayOf(Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_VIDEO)
                } else {
                    arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE , Manifest.permission.WRITE_EXTERNAL_STORAGE)
                }
            var action: () -> Unit ={} // add trigger function in your method to request permissions when they are correct
            val scope = rememberCoroutineScope()
            /*
            Remember you must request storage permissions to be able to access the content of your phone.
            In this case, a rememberLauncherForActivityResult was used, but you could use any other library that you considered appropriate.
            Remember to create a trigger function like "action" since it is recovering the action of displaying the content
            */
            val multiplePermissionResultLauncher = rememberLauncherForActivityResult(
                contract = ActivityResultContracts.RequestMultiplePermissions(),
                onResult = { perms ->
                    scope.launch {
                        if (perms[permissionsToRequest[0]] == true && perms[permissionsToRequest[1]] == true) {
                            action() // Shooting function when permissions are given, pressing the button consumes the content of your phone
                        }
                    }
                }
            )
            AppNameTheme {
                Column{
                     MediaPicker(
                           actionStart = {
                                action = it // Action function triggers by recovering the action of opening the content.
                           },
                           multiMedia = true, // change the value to single selection
                           getMedia = {} // retrieves a list of Mediauser objects which contains the Uri and File of the selected files
                     )
                     Button(
                            onClick  = {
                                   scope.launch{multiplePermissionResultLauncher.launch(permissionsToRequest)}
                            }
                     ){
                         Icon(imageVector = Icons.Rounded.Add, contenteDescription = null)
                     }
                }
            }
        }
    }
}

🧱 Creditos

Licencia

Copyright 2023 luisangeldd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Fetch Video/Picture file from Android device, alternative to the default file manager

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages