feature: Support Native Media Gallery Indexing / scanFile API on Android (Serious Python)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Área
- mobile-dev
Línea de trabajo
Empieza siguiendo la API solicitada page.scan_media(path) o page.storage_paths.scan_file(path) a través del cliente de Flutter y del controlador Dart MethodChannel; después, inspecciona el límite de Android MediaScannerConnection. Se considera terminado cuando un archivo guardado en el almacenamiento público de Android aparece en Gallery y en otras aplicaciones multimedia sin abrir un gestor de archivos.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Duplicate Check
- I have searched the opened issues and there are no duplicates
Describe the requested feature
When building multi-platform Python applications with Flet and compiling them for Android using Serious Python, apps often need to download or save media files (videos, photos, audio) to public user directories (such as the standard Download/ folder).
The Problem
When a file is downloaded or created directly on the filesystem under public storage (e.g., /storage/emulated/0/Download/), other Android apps (like WhatsApp, Instagram, TikTok) and the native system Gallery do not show the new file automatically.
The files are technically present on disk, but they remain invisible to other apps until the user manually opens the Android system File Manager. Opening the File Manager forces a system-level ContentObserver folder scan, which finally registers the files in the Android MediaStore database.
What We Tried (And the JNI / PyJNIus Traps)
We attempted to solve this within Python code using PyJNIus (jnius) to manually trigger the Android MediaScannerConnection.scanFile() API. However, doing this from Python runs into several major JNI and Serious Python structural blocks:
1. PyJNIus Background Thread Attachment Trap
Flet events and background tasks run on Python background worker threads (like asyncio or threading loops). PyJNIus calling Java methods from a background thread fails silently or crashes unless jnius.attach_thread() is explicitly called beforehand.
import jnius
jnius.attach_thread() # Required, but undocumented and highly prone to runtime errors
2. Changing Host Activity Class Names
To initialize MediaScannerConnection, we need the application Context. In Serious Python, finding the host activity via class lookups is brittle because class names vary between Serious Python versions:
- Older:
com.flet.serious_python_android.PythonActivity - Newer:
com.flet.serious_python.PythonActivity - Fallback lookups like
android.app.ActivityThread.currentApplication()frequently returnnullwhen called from Python worker threads.
3. JNI Signature Matching Failures
PyJNIus has trouble converting Python list structures to Java String[] array signatures expected by scanFile(Context, String[], String[], OnScanCompletedListener). Developers have to construct Java arrays manually via JNI reflection:
Array = autoclass('java.lang.reflect.Array')
String = autoclass('java.lang.String')
paths_arr = Array.newInstance(String, len(file_paths)) # Brittle reflection setup
4. Android 9+ Implicit Intent Blocks
Fallback intent broadcasts like android.intent.action.MEDIA_SCANNER_SCAN_FILE are ignored on Android 9+ unless explicitly targeted to the Media Provider package (-p com.android.providers.media), making shell-based workarounds highly complex and security-restricted.
Suggest a solution
To make Flet a truly first-class framework for mobile development, Flet should expose a native, cross-platform media indexing API (for example, page.scan_media(path) or a new page.storage_paths.scan_file(path) service method).
How it should work under the hood:
- The Flet Flutter client should handle the media scanner connection natively on the Dart side.
- In Dart, triggering a media scan on Android is extremely simple and does not suffer from classloader or background-thread JNI issues:
// Dart side handler import 'package:flutter/services.dart'; // Native MethodChannel triggers MediaScannerConnection.scanFile on the Android Activity thread - By delegating this to the Flutter shell, Python developers wouldn't need to write brittle PyJNIus wrappers, deal with JNI JVM thread-attachments, or worry about changing package class names between Serious Python releases.
This feature is essential for any Flet application that downloads user-facing files (photos, videos, PDF documents, audio) to public directories on Android.
Screenshots
No response
Additional details
No response
- Lenguaje dominante
- Python
- Estrellas
- 17.1k
- Forks
- 708
- Merge medio
- 1 d 17 h
- PR fusionados (30 d)
- 46
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de flet-dev/flet
-
bug controls
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
bug: Interactive Viewer renders grey text when passed alignmentPosiblemente ocupada @ndonkoHenri la tomó hace 6 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
flet-dev/flet#6744 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
feature: Dropdown on_click eventAbiertofeature request
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
Los mantenedores suelen responder en 1 día
Todos los issues de flet-dev/flet
Issues similares
-
repo-audit
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
scverse/repo-health#20 ·
Los mantenedores suelen responder en 1 día
-
/context/prime scope override double-prefixes an entity-ref project and drops its scoped memoriesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
phasespace-labs/palinode#232 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
collective/icalendar#1858 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
lfx-mcp cannot supply global variables: LangflowClient drops X-LANGFLOW-GLOBAL-VAR-* from envAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
langflow-ai/langflow#15496 ·
Los mantenedores suelen responder en 1 día