Repository navigation
Replies: 1 comment
|
For a packaged Android app, copy the bundled file into the app's private storage using Flet's paths, rather than hard-coding import os
import shutil
from pathlib import Path
import flet as ft
def main(page: ft.Page):
# Example file bundled as assets/seed.db
source = Path(os.environ["FLET_ASSETS_DIR"]) / "seed.db"
destination = Path(os.environ["FLET_APP_STORAGE_DATA"]) / "app.db"
destination.parent.mkdir(parents=True, exist_ok=True)
if not destination.exists():
shutil.copyfile(source, destination)
page.add(ft.Text(str(destination)))
ft.run(main, assets_dir="assets")The existence check prevents replacing an edited database on every launch. Copy the bundled seed; keep subsequent writes in the destination. One distinction: The current assets guide documents |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Question
How can I move or copy files from the assets directory to Android /data/user/0/com.mycompany.flet_adb/files ?
Code sample
No response
Error message
No response
------------------------------------------------------
All reactions