Struct ndk_context::AndroidContext
source · [−]pub struct AndroidContext { /* private fields */ }
Expand description
AndroidContext
provides the pointers required to interface with the jni on Android
platforms.
Implementations
sourceimpl 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
sourceimpl Clone for AndroidContext
impl Clone for AndroidContext
sourcefn clone(&self) -> AndroidContext
fn clone(&self) -> AndroidContext
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for AndroidContext
impl Debug for AndroidContext
impl Copy for AndroidContext
Auto Trait Implementations
impl RefUnwindSafe for AndroidContext
impl !Send for AndroidContext
impl !Sync for AndroidContext
impl Unpin for AndroidContext
impl UnwindSafe for AndroidContext
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more