We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5278

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)   

Description Huki 2020-09-02 13:26:56 UTC
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");
```
Comment 1 Sylvain 2020-09-02 17:39:45 UTC
Thanks ! fixed in https://hg.libsdl.org/SDL/rev/8f1abe5e7d8f
Comment 2 Sylvain 2020-09-02 17:40:19 UTC
marked as fixed