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
impl NativeActivity
Sourcepub unsafe fn from_ptr(ptr: NonNull<ANativeActivity>) -> Self
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
.
Sourcepub fn ptr(&self) -> NonNull<ANativeActivity>
pub fn ptr(&self) -> NonNull<ANativeActivity>
The pointer to the native ANativeActivity
Source§impl NativeActivity
Methods that relate to fields of the struct itself
impl NativeActivity
Methods that relate to fields of the struct itself
The relevant NDK docs can be found here.
Sourcepub fn sdk_version(&self) -> i32
pub fn sdk_version(&self) -> i32
The platform’s SDK version code
Sourcepub fn internal_data_path(&self) -> &Path
pub fn internal_data_path(&self) -> &Path
Path to this application’s internal data directory
Sourcepub fn external_data_path(&self) -> &Path
pub fn external_data_path(&self) -> &Path
Path to this application’s external (removable, mountable) data directory
Sourcepub fn asset_manager(&self) -> AssetManager
pub fn asset_manager(&self) -> AssetManager
This app’s asset manager, which can be used to access assets from the .apk
file.
Sourcepub unsafe fn set_instance(&mut self, data: *mut c_void)
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.
Sourcepub fn vm(&self) -> *mut JavaVM
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 ...
Sourcepub fn activity(&self) -> jobject
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§impl NativeActivity
Methods that relate to ANativeActivity_*
functions.
impl NativeActivity
Methods that relate to ANativeActivity_*
functions.
The relevant NDK docs can be found here.
Sourcepub fn show_soft_input(&self, force: bool)
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.
Sourcepub fn hide_soft_input(&self, not_always: bool)
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.
Sourcepub fn set_window_format(&self, format: HardwareBufferFormat)
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.
Sourcepub fn set_window_flags(
&self,
add_flags: WindowFlags,
remove_flags: WindowFlags,
)
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.