| Summary: | [Feature request] SDL_AndroidRequestPermission | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Huki <gk7huki> |
| Component: | *don't know* | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | API change | ||
| Priority: | P2 | CC: | sylvain.becker |
| Version: | 2.0.12 | ||
| Hardware: | All | ||
| OS: | Android (All) | ||
Thanks ! fixed in https://hg.libsdl.org/SDL/rev/8f1abe5e7d8f marked as fixed |
Android 6.0 and above use a runtime permission model where certain permissions must be requested at runtime in addition to having them in the manifest. Doing this in native code rather than Java helps keep things properly synchronized. As of 2.0.12, SDL already has a private Android_JNI_RequestPermission() that's used to get RECORD_AUDIO permission in the OpenSLES backend. Likewise, my code needs EXTERNAL_STORAGE perms. It'd be nice to have this as a public API instead. Currently I added a public API that wraps around Android_JNI_RequestPermission(). In `include/SDL_system.h`: ``` /** \brief Request permissions at runtime. This blocks the calling thread until the permission is granted or denied. Returns SDL_TRUE if the permission was granted. */ extern DECLSPEC SDL_bool SDLCALL SDL_AndroidRequestPermission(const char *permission); ``` In `src/core/android/SDL_android.c`: ``` SDL_bool SDL_AndroidRequestPermission(const char *permission) { return Android_JNI_RequestPermission(permission); } ``` Then my code can call: ``` SDL_AndroidRequestPermission("android.permission.READ_EXTERNAL_STORAGE"); SDL_AndroidRequestPermission("android.permission.WRITE_EXTERNAL_STORAGE"); ```