docs.rs failed to build android-permissions-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Android Permissions for Rust
A Rust library for handling Android permissions in Android apps written in Rust with the Android NDK. This library provides a simple and idiomatic Rust interface for checking and requesting Android permissions.
Features
- Check if a permission is granted
- Request one or multiple permissions asynchronously
- Predefined constants for common Android permissions
- Automatic handling of permission request callbacks
- Seamless integration with Android NDK projects
Installation
Add this to your Cargo.toml
:
[]
= "0.1.0"
Setup
1. Add Permissions to AndroidManifest.xml
Add the required permissions to your AndroidManifest.xml
:
2. Configure Cargo.toml for Cargo APK
In your Cargo.toml
, add the permissions metadata:
[[]]
= "android.permission.WRITE_EXTERNAL_STORAGE"
[[]]
= "android.permission.CAMERA"
Usage
Here's a complete example of how to use the library:
use ;
use ;
use ;
use HashMap;
use Future;
async
API Reference
init(vm: JavaVM, activity: JObject) -> Result<PermissionManager>
Initialize the permission manager with the JavaVM and Activity references.
PermissionManager.check(permission: &Permission) -> Result<bool>
Check if a specific permission is granted.
PermissionManager.request(permissions: &[&Permission]) -> Future<Result<HashMap<String, bool>>>
Request one or more permissions from the user. Returns a future that resolves with a map of permission names to their granted status.
Predefined Permissions
The library provides constants for common Android permissions:
CAMERA
READ_EXTERNAL_STORAGE
WRITE_EXTERNAL_STORAGE
ACCESS_FINE_LOCATION
ACCESS_COARSE_LOCATION
RECORD_AUDIO
POST_NOTIFICATIONS
READ_MEDIA_IMAGES
READ_MEDIA_VIDEO
READ_MEDIA_AUDIO
READ_CONTACTS
WRITE_CONTACTS
GET_ACCOUNTS
READ_CALENDAR
WRITE_CALENDAR
SEND_SMS
RECEIVE_SMS
READ_SMS
CALL_PHONE
READ_PHONE_STATE
License
MIT