Support Native Media Gallery Indexing / scanFile API on Android (Serious Python)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu bằng cách lần theo handler phía Dart của Flutter client và entry point MethodChannel được đề xuất, sau đó kiểm tra cách Serious Python cung cấp các dịch vụ cho Python. Công việc được hoàn tất khi một API quét media đa nền tảng được expose và các tệp Android trở nên hiển thị với MediaStore native mà không cần các workaround của PyJNIus.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Dart
- Star
- 325
- Fork
- 46
- Merge trung bình
- 14 giờ 53 phút
- Pull request đã merge (30 ngày)
- 5
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của flet-dev/serious-python
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
flet-dev/serious-python#169 ·
-
iOS Build Failure: Missing site-xcframeworks Directory in serious_python_darwin PhaseScriptExecutionĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
flet-dev/serious-python#168 ·
-
Update docs for site-packagesCó thể làm lại được @FeodorFitsner đã nhận 558 ngày trước và không có pull request nào đang mở. Đang mởdocumentation
flet-dev/serious-python#157 · 1 bình luận · 1 người được giao ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
flet-dev/serious-python#133 · 2 bình luận ·
-
Fail to debug run_exampleĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
flet-dev/serious-python#117 ·
Tất cả issue của flet-dev/serious-python
Issue tương tự
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
flame-engine/flame#4067 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
mrgnhnt96/zonai#37 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
google/skills_lint.dart#58 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] attempt to index nil valueĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
nvim-flutter/flutter-tools.nvim#557 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
lugassawan/swe-workbench#755 ·
Maintainer thường phản hồi trong vòng 1 ngày