Struct NativeActivity

Source
pub struct NativeActivity { /* private fields */ }
Expand description

A native ANativeActivity *

This is either provided in ffi::ANativeActivity_onCreate(), or accessible through ndk_glue::native_activity().

Implementations§

Source§

impl NativeActivity

Source

pub unsafe fn from_ptr(ptr: NonNull<ANativeActivity>) -> Self

Create a NativeActivity from a pointer

§Safety

By calling this function, you assert that it is a valid pointer to a native ffi::ANativeActivity.

Source

pub fn ptr(&self) -> NonNull<ANativeActivity>

The pointer to the native ANativeActivity

Source§

impl NativeActivity

Methods that relate to fields of the struct itself

The relevant NDK docs can be found here.

Source

pub fn sdk_version(&self) -> i32

The platform’s SDK version code

Source

pub fn internal_data_path(&self) -> &Path

Path to this application’s internal data directory

Source

pub fn external_data_path(&self) -> &Path

Path to this application’s external (removable, mountable) data directory

Source

pub fn asset_manager(&self) -> AssetManager

This app’s asset manager, which can be used to access assets from the .apk file.

Source

pub fn instance(&self) -> *mut c_void

Instance data associated with the activity

Source

pub unsafe fn set_instance(&mut self, data: *mut c_void)

Set the instance data associated with the activity

§Safety

This can invalidate assumptions held by ndk-glue, as well as cause data races with concurrent access to the instance data.

Source

pub fn vm(&self) -> *mut JavaVM

This process’s JavaVM object.

Usage with jni crate:

let vm_ptr = native_activity.vm();
let vm = unsafe { jni::JavaVM::from_raw(vm_ptr) }.unwrap();
let env = vm.attach_current_thread();
// Do JNI with env ...
Source

pub fn activity(&self) -> jobject

The android.app.NativeActivity instance

In the JNI, this is named clazz; however, as the docs say, “it should really be named ‘activity’ instead of ‘clazz’, since it’s a reference to the NativeActivity instance”.

Source

pub unsafe fn obb_path(&self) -> &Path

Path to the directory with the application’s OBB files.

§Safety

Only available as of Honeycomb (Android 3.0+, API level 11+)

Source§

impl NativeActivity

Methods that relate to ANativeActivity_* functions.

The relevant NDK docs can be found here.

Source

pub fn finish(&self)

Sends a destroy event to the activity and stops it.

Source

pub fn show_soft_input(&self, force: bool)

Shows the IME (the on-screen keyboard).

If force is true, the SHOW_FORCED flag is used; otherwise, the SHOW_IMPLICIT flag is used. Depending on the value of this flag, the hide_soft_input method with behave differently. See the relevant javadoc for more information.

Source

pub fn hide_soft_input(&self, not_always: bool)

Hides the IME (the on-screen keyboard).

If not_always is true, the HIDE_NOT_ALWAYS flag is used; otherwise, the HIDE_IMPLICIT_ONLY flag is used. Depending on the value of this flag and the way the IME was shown, it may or may not be hidden. See the relevant javadoc for more information.

Source

pub fn set_window_format(&self, format: HardwareBufferFormat)

Change the window format of the given activity.

Calls getWindow().setFormat() of the given activity. Note that this method can be called from any thread; it will send a message to the main thread of the process where the Java finish call will take place.

Source

pub fn set_window_flags( &self, add_flags: WindowFlags, remove_flags: WindowFlags, )

Change the window flags of the given activity.

Calls getWindow().setFlags() of the given activity.

Note that this method can be called from any thread; it will send a message to the main thread of the process where the Java finish call will take place.

Trait Implementations§

Source§

impl Debug for NativeActivity

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Send for NativeActivity

Source§

impl Sync for NativeActivity

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.