love2d / love-android

Android build setup for LÖVE.
https://love2d.org
Other
200 stars 70 forks source link

Permission changes for accessing files on external storage (Android 11+) #242

Closed 9912 closed 1 year ago

9912 commented 1 year ago

Hi, i've succeeded to access files on external storage in order to use nativefs.lua with nativefs.mount() function.

Tested on device: Redmi 9A (armeabi-v7a) - MIUI 12.5 + Android 11

How it'll work: -An additional permission is added to app\src\main\AndroidManifest.xml to grant access -Some code is added to love\src\main\java\org\love2d\android\GameActivity.java to check the aforementioned permission, on first run, Android will pop up the files access permission config to enable LÖVE to access all files, after that, the no-game screen appears. After that point, you can put some code to /Android/data/org.love2d.android/files/games/lovegame and use nativefs.lua to mount zip files or read any file from internal storage (generally from /storage/emulated/0)

Caveats and reccomendations: -Since is a (very) sensitive permission, Google Play will reject the app from publishing, so the recommendation is to distribute a Google Play version and either (or both) F-Droid and standalone APK like Total Commander did.

MikuAuahDark commented 1 year ago

Code which expects arbitrary directory access is expected not to work in mobile devices due to sandboxing. This includes nativefs.

I don't have plan to change the way it works for now in LOVE 11, but this is probably a good change to consider in LOVE 12.