2 releases

0.1.1 Apr 19, 2022
0.1.0 Feb 14, 2022

#232 in Development tools

Download history 75270/week @ 2024-09-17 82366/week @ 2024-09-24 85728/week @ 2024-10-01 84037/week @ 2024-10-08 82743/week @ 2024-10-15 89146/week @ 2024-10-22 86883/week @ 2024-10-29 90414/week @ 2024-11-05 87084/week @ 2024-11-12 86093/week @ 2024-11-19 83012/week @ 2024-11-26 91723/week @ 2024-12-03 90888/week @ 2024-12-10 78475/week @ 2024-12-17 60264/week @ 2024-12-24 48568/week @ 2024-12-31

292,539 downloads per month
Used in 3,206 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