Support Native Media Gallery Indexing / scanFile API on Android (Serious Python)
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 45/100
Direção de pesquisa
Comece rastreando o handler do lado Dart do cliente Flutter e o ponto de entrada MethodChannel proposto; em seguida, inspecione como o Serious Python expõe serviços para Python. O trabalho estará concluído quando uma API de varredura de mídia multiplataforma for exposta e os arquivos do Android ficarem visíveis para o MediaStore nativo sem exigir workarounds do PyJNIus.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Context
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.
Proposed Solution (Feature Request)
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.
- Linguagem predominante
- Dart
- Estrelas
- 325
- Forks
- 46
- Merge médio
- 14h 53min
- PRs com merge (30d)
- 5
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de flet-dev/serious-python
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
flet-dev/serious-python#169 ·
-
iOS Build Failure: Missing site-xcframeworks Directory in serious_python_darwin PhaseScriptExecutionAberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 42/100
flet-dev/serious-python#168 ·
-
Update docs for site-packagesTalvez livre de novo @FeodorFitsner assumiu há 558 dias e não há nenhum pull request aberto. Abertadocumentation
flet-dev/serious-python#157 · 1 comentário · 1 responsável ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
flet-dev/serious-python#133 · 2 comentários ·
-
Fail to debug run_exampleAberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
flet-dev/serious-python#117 ·
Todas as issues de flet-dev/serious-python
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
immich-app/immich#31955 ·
Mantenedores costumam responder em até 1 dia
-
bug triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
fluttercommunity/plus_plugins#3994 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
-
Smart charging: USB charger re-assert is starved during BLE scans, so the tablet never dischargesAbertabug ready-for-agent
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
decentespresso/decaid#931 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 92/100
flame-engine/flame#4067 ·
Mantenedores costumam responder em até 1 dia