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 - [Feature request] SDL_AndroidRequestPermission
Summary: [Feature request] SDL_AndroidRequestPermission
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 2.0.12
Hardware: All Android (All)
: P2 API change
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-02 13:26 UTC by Huki
Modified: 2020-09-02 17:40 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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