2 releases

0.1.1 Apr 19, 2022
0.1.0 Feb 14, 2022

#198 in Development tools

Download history 19512/week @ 2022-11-28 19985/week @ 2022-12-05 19391/week @ 2022-12-12 17970/week @ 2022-12-19 12222/week @ 2022-12-26 18559/week @ 2023-01-02 22484/week @ 2023-01-09 20559/week @ 2023-01-16 21748/week @ 2023-01-23 24269/week @ 2023-01-30 29542/week @ 2023-02-06 34331/week @ 2023-02-13 25424/week @ 2023-02-20 27543/week @ 2023-02-27 30187/week @ 2023-03-06 26863/week @ 2023-03-13

113,505 downloads per month
Used in 1,343 crates (14 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