2 releases

0.1.1 Apr 19, 2022
0.1.0 Feb 14, 2022

#247 in Development tools

Download history 51264/week @ 2024-02-28 53652/week @ 2024-03-06 50393/week @ 2024-03-13 55433/week @ 2024-03-20 56828/week @ 2024-03-27 51757/week @ 2024-04-03 61822/week @ 2024-04-10 63283/week @ 2024-04-17 61629/week @ 2024-04-24 62111/week @ 2024-05-01 64178/week @ 2024-05-08 76534/week @ 2024-05-15 70705/week @ 2024-05-22 78680/week @ 2024-05-29 80353/week @ 2024-06-05 63697/week @ 2024-06-12

309,412 downloads per month
Used in 2,592 crates (22 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