Expand description
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()?;
Structs§
- Android
Context AndroidContext
provides the pointers required to interface with the jni on Android platforms.
Functions§
- android_
context - Main entry point to this crate. Returns an
AndroidContext
. - initialize_
android_ ⚠context - Initializes the
AndroidContext
.AndroidContext
is initialized by ndk-glue beforemain
is called. - release_
android_ ⚠context - Removes the
AndroidContext
. It is released by ndk-glue when the activity is finished and destroyed.