2 releases

0.1.1 Apr 19, 2022
0.1.0 Feb 14, 2022

#226 in Development tools

Download history 26281/week @ 2023-12-23 35424/week @ 2023-12-30 44674/week @ 2024-01-06 43742/week @ 2024-01-13 46320/week @ 2024-01-20 44094/week @ 2024-01-27 50765/week @ 2024-02-03 46811/week @ 2024-02-10 42149/week @ 2024-02-17 49618/week @ 2024-02-24 53931/week @ 2024-03-02 49732/week @ 2024-03-09 52900/week @ 2024-03-16 58265/week @ 2024-03-23 53352/week @ 2024-03-30 47475/week @ 2024-04-06

220,578 downloads per month
Used in 2,372 crates (18 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