sdlRequestAndroidPermission function
- String? permission,
- Pointer<
NativeFunction< cb,SdlRequestAndroidPermissionCallback> > - Pointer<
NativeType> userdata
Request permissions at runtime, asynchronously.
You do not need to call this for built-in functionality of SDL; recording from a microphone or reading images from a camera, using standard SDL APIs, will manage permission requests for you.
This function never blocks. Instead, the app-supplied callback will be called when a decision has been made. This callback may happen on a different thread, and possibly much later, as it might wait on a user to respond to a system dialog. 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.
If the request submission fails, this function returns -1 and the callback will NOT be called, but this should only happen in catastrophic conditions, like memory running out. Normally there will be a yes or no to the request through the callback.
For the permission
parameter, choose a value from here:
https://developer.android.com/reference/android/Manifest.permission
\param permission the permission to request. \param cb the callback to trigger when the request has a response. \param userdata an app-controlled pointer that is passed to the callback. \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.
\threadsafety It is safe to call this function from any thread.
\since This function is available since SDL 3.1.3.
extern SDL_DECLSPEC bool SDLCALL SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermissionCallback cb, void *userdata)
Implementation
bool sdlRequestAndroidPermission(
String? permission,
Pointer<NativeFunction<SdlRequestAndroidPermissionCallback>> cb,
Pointer<NativeType> userdata) {
final sdlRequestAndroidPermissionLookupFunction = libSdl3.lookupFunction<
Uint8 Function(
Pointer<Utf8> permission,
Pointer<NativeFunction<SdlRequestAndroidPermissionCallback>> cb,
Pointer<NativeType> userdata),
int Function(
Pointer<Utf8> permission,
Pointer<NativeFunction<SdlRequestAndroidPermissionCallback>> cb,
Pointer<NativeType> userdata)>('SDL_RequestAndroidPermission');
final permissionPointer =
permission != null ? permission.toNativeUtf8() : nullptr;
final result = sdlRequestAndroidPermissionLookupFunction(
permissionPointer, cb, userdata) ==
1;
calloc.free(permissionPointer);
return result;
}