Introducci贸n a la Integraci贸n Nativa en Android

1

Integra APIs Nativas en Android

2

Creaci贸n proyecto base

Google Maps SDK

3

C贸mo crear una API key para Google Maps en Google Cloud

4

Creaci贸n de marcadores en Google Maps con Jetpack Compose

5

C贸mo dibujar rutas en mapas usando polil铆neas en Jetpack Compose

6

C贸mo enfocar autom谩ticamente mapas usando Camera Update Factory

Quiz: Google Maps SDK

Servicios de Localizaci贸n

7

Uso de Flows en Kotlin para Controlar Intervalos de Tiempo y Emisi贸n de Datos

8

C贸mo simular ubicaci贸n en emuladores y dispositivos reales

9

Creaci贸n de Modelos y C谩lculos de Localizaci贸n con Clean Architecture

10

Implementaci贸n de Localizaci贸n en Android Usando Flows

11

Inyecci贸n de dependencia para seguimiento de localizaci贸n en Android

12

Uso de StateFlows para rastrear ubicaci贸n en aplicaciones Android

13

Location Tracker

14

Implementaci贸n de Location Tracker con Inyecci贸n de Dependencias

Quiz: Servicios de Localizaci贸n

Integraci贸n Maps con Localizaci贸n

15

Integraci贸n de mapas din谩micos con CameraPositionState en Android

16

Creaci贸n y uso de polil铆neas en mapas con datos reales

17

Creaci贸n de una pantalla de mapa con Intents y estados en Jetpack Compose

18

Creaci贸n de un ViewModel para Seguimiento de Localizaci贸n en Android

Quiz: Integraci贸n Maps con Localizaci贸n

Manejo de permisos

19

Gesti贸n de permisos en Android para localizaci贸n, c谩mara y notificaciones

20

C贸mo implementar di谩logos para solicitar permisos en Android

21

Manejo de permisos de localizaci贸n y notificaci贸n en Android

22

C贸mo gestionar permisos en Android con Jetpack Compose

Quiz: Manejo de permisos

Integraci贸n c谩mara

23

Integraci贸n de c谩mara en Android con Photo Handler y manejo de permisos

24

Convierte Bitmaps a ByteArrays en Android con Kotlin

25

Creaci贸n de intents y estados UI para c谩mara en Android con Kotlin

26

Implementaci贸n de funciones clave en ViewModel para c谩mara Android

27

Integrar C谩maraX en Jetpack Compose para Android

28

Captura y previsualizaci贸n de fotos en Android con Jetpack Compose

29

C贸mo Mostrar Fotos en Marcadores de Ubicaci贸n en Mapas con Jetpack Compose

Quiz: Integraci贸n c谩mara

Servicios en Android

30

Implementaci贸n de servicios en Android: normal services y foreground services

31

Implementar Foreground Services en Android para Persistencia en Segundo Plano

Quiz: Servicios en Android

Transmisiones en Android (Broadcast)

32

Implementaci贸n de BroadcastReceiver en Android para Escuchar Eventos del Sistema

33

Pruebas finales y cierre

You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

0 D铆as
14 Hrs
3 Min
3 Seg

Integraci贸n de c谩mara en Android con Photo Handler y manejo de permisos

23/33
Resources

Properly integrating the camera into an Android application requires careful handling of two key points: permissions management and local storage of the photos taken. Below we will see how to achieve these goals using an interface called Photo Handler, whose main task will be the efficient and orderly management of the process.

How to manage photo storage with Photo Handler?

First of all, we propose to create a package in the Domain layer called Camera, inside which a vital file called Photo Handler will be established. This interface will define specific activities related to the camera throughSuspend Functions. Among the defined activities are:

  • Save Picture Preview: Save the current picture as a file, possibly being null.
  • Uncancel Preview: Cancels the existing preview.
  • Get Current Preview Photo: Exposes the current preview by means of aFlow that can return a ByteArray or null.
  • Clear Photos: Clears all locally saved images.
  • Unphoto Preview: Performs an intermediate operation by exposing a ByteArray.

In addition, it provides access to a list of stored photos through a stream that manipulates files directly stored in the system.

What is the general flow for capturing and storing photos?

There is a clearly defined process for capture and storage:

  1. When a photo is taken using CameraX, an initial preview (ByteArray) is generated.
  2. This preview is exposed through a stream using Get Current Preview Photo.
  3. If the photo is accepted by the user, the user runs Save Picture Preview, converting the preview into a permanent file.
  4. If it is not accepted, it is allowed to cancel it with Uncancel Preview.
  5. The Get Photos method is used to get a complete list of previously stored images.
  6. At the end of the process and to free space or resources, Clear Photos is invoked.

Each method has its specific purpose, optimizing the user experience and maintaining an efficient data flow.

How is Photo Handler implemented in the data module?

The actual implementation occurs in the Data module, creating a responsible class called HandlerImplementation that receives the application context as the main dependency. This context allows to easily define a directory called Photos, where effectively the captured images will be stored.

The access to the images is configured with the following logic: - It is verified if the main directory exists, and if it is not created yet, with the mkdirs() function it is automatically generated - Two local variables called CurrentPreviewPhoto (a MutableStateFlow of ByteArray) and a MutableStateFlow list are managed to keep track of all the photos.

To get saved images, it uses specific functions: - loadPhotos(): Loads the saved photos filtering by standard extensions (jpg, jpeg, png) - Sorts the results by modification date to obtain an organized visualization.

The core implementation corresponds to the methods defined in the interface, clarifying what happens with each action performed by the user:

  • When an onPhotoPreview is performed, it updates the current photo in the preview.
  • With onCancelPreview, it clears the preview reference.
  • The getPhotos function returns the stored photos as a state stream.
  • clearPhotos handles the safe deletion of files, executing that action in a separate thread via Dispatchers.IO.
  • Finally, the safePicturePreview method performs the actual physical file write, adding timestamps for easier management later.

These steps contribute to a robust and efficient integration of camera and storage management in Android applications with good practices and effective resource management.

Contributions 0

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?