2 releases

0.1.1 Apr 19, 2022
0.1.0 Feb 14, 2022

#238 in Development tools

Download history 47784/week @ 2023-11-21 45483/week @ 2023-11-28 48536/week @ 2023-12-05 41527/week @ 2023-12-12 36508/week @ 2023-12-19 27251/week @ 2023-12-26 40809/week @ 2024-01-02 43214/week @ 2024-01-09 44773/week @ 2024-01-16 45449/week @ 2024-01-23 47065/week @ 2024-01-30 49094/week @ 2024-02-06 45790/week @ 2024-02-13 43020/week @ 2024-02-20 50549/week @ 2024-02-27 45443/week @ 2024-03-05

191,610 downloads per month
Used in 2,275 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