2 releases

0.1.1 Apr 19, 2022
0.1.0 Feb 14, 2022

#228 in Development tools

Download history 81806/week @ 2024-10-10 86217/week @ 2024-10-17 86548/week @ 2024-10-24 89755/week @ 2024-10-31 85875/week @ 2024-11-07 90525/week @ 2024-11-14 83526/week @ 2024-11-21 87841/week @ 2024-11-28 89914/week @ 2024-12-05 89050/week @ 2024-12-12 61066/week @ 2024-12-19 60370/week @ 2024-12-26 79990/week @ 2025-01-02 96527/week @ 2025-01-09 91077/week @ 2025-01-16 80084/week @ 2025-01-23

353,700 downloads per month
Used in 3,290 crates (27 directly)

MIT/Apache

6KB

ndk-context

Provides a stable api to rust crates for interfacing with the Android platform. It is initialized by the runtime, usually ndk-glue, but could also be initialized by Java or Kotlin code when embedding in an existing Android project.


lib.rs:

Provides a stable api to rust crates for interfacing with the Android platform. It is initialized by the runtime, usually ndk-glue, but could also be initialized by Java or Kotlin code when embedding in an existing Android project.

let ctx = ndk_context::android_context();
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
let env = vm.attach_current_thread();
let class_ctx = env.find_class("android/content/Context")?;
let audio_service = env.get_static_field(class_ctx, "AUDIO_SERVICE", "Ljava/lang/String;")?;
let audio_manager = env
    .call_method(
        ctx.context() as jni::sys::jobject,
        "getSystemService",
        "(Ljava/lang/String;)Ljava/lang/Object;",
        &[audio_service],
    )?
    .l()?;

No runtime deps