SDL_RequestAndroidPermission(3)

πŸ’– SDL_RequestAndroidPermission(3) πŸ’–

okay bestie, you're in the SDL3 FUNCTIONS section of the SDL3 manual, and today's main character is SDL_RequestAndroidPermission β€” the one that asks Android for permissions at runtime, asynchronously. no cap. 🫢


✨ NAME ✨

SDL_RequestAndroidPermission β€” Request permissions at runtime, asynchronously. πŸŽ€


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_system.h>

bool SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermissionCallback cb, void *userdata);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so first things first, bestie: you do not need to call this for built-in functionality of SDL. like, recording from a microphone or reading images from a camera using standard SDL APIs? that already manages permission requests for you. SDL is the responsible older sibling here. πŸ’…

This function never blocks. literally never. instead, the app-supplied callback gets called when a decision has been made. and lowkey, that callback may happen on a different thread, and possibly much later, because it might be waiting on a user to respond to a system dialog. like, the user is out here living their life, staring at a popup, deciding your fate. 😭

If permission has already been granted for a specific entitlement, the callback will still fire β€” probably on the current thread and before this function returns. so don't go assuming silence means nothing happened. πŸ™ˆ

If the request submission fails, this function returns -1 and the callback will NOT be called. but ngl, that should only happen in catastrophic conditions, like memory running out. normally there will be a yes or no to the request through the callback. so most of the time it's giving... a decision. either way. πŸ“

For the permission parameter, choose a value from here:

https://developer.android.com/reference/android/Manifest.permission

that's the vibe check for what string to actually pass in. πŸ‘‘


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • permission β€” the permission to request. 🌈
  • cb β€” the callback to trigger when the request has a response. ✨
  • userdata β€” an app-controlled pointer that is passed to the callback. 🫢

πŸ”₯ RETURN VALUE πŸ”₯

Returns true if the request was submitted, false if there was an error submitting. The result of the request is only ever reported through the callback, not this return value. so do not β€” I repeat, do NOT β€” read this as the answer to your permission question. it's just "did we manage to send the ask". periodt. πŸ’€


🧚 THREAD SAFETY 🧚

It is safe to call this function from any thread. main character energy from any thread. slay. πŸ’œ


⭐ AVAILABILITY ⭐

This function is available since SDL 3.2.0. so if you're on something older, no permission asking for you, bestie. 😭


okay that's the whole page, you ate it, go request some permissions responsibly. this was the SDL_RequestAndroidPermission(3) page from Simple Directmedia Layer, version SDL 3.4.18 β€” huge thanks to the SDL besties for keeping the docs iconic. bye babe! πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from