Support Native Media Gallery Indexing / scanFile API on Android (Serious Python)
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 45/100
Piste de recherche
Commencez par suivre le handler côté Dart du client Flutter et le point d’entrée MethodChannel proposé, puis examinez comment Serious Python expose des services à Python. Le travail est terminé lorsqu’une API de scan multimédia multiplateforme est exposée et que les fichiers Android deviennent visibles pour le MediaStore natif sans nécessiter de workarounds PyJNIus.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Dart
- Étoiles
- 325
- Forks
- 46
- Merge moyen
- 19 h 50 min
- PR mergées (30 j)
- 4
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de flet-dev/serious-python
-
Difficulté 2/5 1-3 heures Accessibilité débutants 55/100
flet-dev/serious-python#254 ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
flet-dev/serious-python#169 ·
-
iOS Build Failure: Missing site-xcframeworks Directory in serious_python_darwin PhaseScriptExecutionOuverte
Difficulté 3/5 1-2 jours Accessibilité débutants 42/100
flet-dev/serious-python#168 ·
-
Update docs for site-packagesPeut-être à nouveau libre @FeodorFitsner l’a pris il y a 568 jours, et aucune pull request n’est ouverte. Ouvertedocumentation
flet-dev/serious-python#157 · 1 commentaire · 1 personne assignée ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
flet-dev/serious-python#133 · 2 commentaires ·
Toutes les issues de flet-dev/serious-python
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
aaronified/fluenough#466 ·
Les mainteneurs répondent en général sous 1 jour
-
difficulty: easy duration: small priority: medium type: bug
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
duobaseio/forui#1215 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
bug Done
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
InlitX/GymMane#183 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Use getApplicationSupportDirectory() of path_provider instead of getApplicationDocumentsDirectory()Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
brandonp2412/Flexify#387 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
fix(very_good_flutter_plugin): Linux plugin does not compile the Pigeon sourcesPeut-être pris @marcossevilla l’a pris il y a 2 jours. Ouvertebug product: very_good_flutter_plugin
Difficulté 1/5 1-3 heures Accessibilité débutants 78/100
VeryGoodOpenSource/very_good_templates#654 ·
Les mainteneurs répondent en général sous 1 jour