pub struct AndroidContext { /* private fields */ }
Expand description
AndroidContext
provides the pointers required to interface with the jni on Android
platforms.
Implementations§
Source§impl AndroidContext
impl AndroidContext
Sourcepub fn vm(self) -> *mut c_void
pub fn vm(self) -> *mut c_void
A handle to the JavaVM
object.
Usage with jni crate:
let ctx = ndk_context::android_context();
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
let env = vm.attach_current_thread();
Sourcepub fn context(self) -> *mut c_void
pub fn context(self) -> *mut c_void
A handle to an android.content.Context.
In most cases this will be a ptr to an Activity
, but this isn’t guaranteed.
Usage with jni crate:
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()?;
Trait Implementations§
Source§impl Clone for AndroidContext
impl Clone for AndroidContext
Source§fn clone(&self) -> AndroidContext
fn clone(&self) -> AndroidContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for AndroidContext
impl Debug for AndroidContext
impl Copy for AndroidContext
Auto Trait Implementations§
impl Freeze for AndroidContext
impl RefUnwindSafe for AndroidContext
impl !Send for AndroidContext
impl !Sync for AndroidContext
impl Unpin for AndroidContext
impl UnwindSafe for AndroidContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more