2 releases

0.1.1 Apr 19, 2022
0.1.0 Feb 14, 2022

#238 in Development tools

Download history 91153/week @ 2024-11-15 80636/week @ 2024-11-22 91747/week @ 2024-11-29 88907/week @ 2024-12-06 88071/week @ 2024-12-13 53940/week @ 2024-12-20 65316/week @ 2024-12-27 85070/week @ 2025-01-03 96487/week @ 2025-01-10 91370/week @ 2025-01-17 93406/week @ 2025-01-24 93925/week @ 2025-01-31 160468/week @ 2025-02-07 180726/week @ 2025-02-14 217216/week @ 2025-02-21 201145/week @ 2025-02-28

776,114 downloads per month
Used in 3,394 crates (29 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