2 releases

0.1.1 Apr 19, 2022
0.1.0 Feb 14, 2022

#273 in Development tools

Download history 73421/week @ 2024-06-20 72882/week @ 2024-06-27 67646/week @ 2024-07-04 67079/week @ 2024-07-11 69237/week @ 2024-07-18 71822/week @ 2024-07-25 70092/week @ 2024-08-01 75003/week @ 2024-08-08 75412/week @ 2024-08-15 85583/week @ 2024-08-22 70766/week @ 2024-08-29 80865/week @ 2024-09-05 77372/week @ 2024-09-12 75526/week @ 2024-09-19 82528/week @ 2024-09-26 74009/week @ 2024-10-03

322,194 downloads per month
Used in 2,908 crates (23 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