#[repr(transparent)]pub struct Env(pub *mut *const [*const c_void; 234]);Expand description
A JNI environment pointer, valid only on the thread that produced it.
repr(transparent) because the VM passes this as a bare JNIEnv* to every
native method — it must have exactly a pointer’s layout.
Tuple Fields§
§0: *mut *const [*const c_void; 234]Implementations§
Source§impl Env
impl Env
pub fn version(&self) -> i32
Sourcepub fn find_class(&self, name: &str) -> Option<JClass>
pub fn find_class(&self, name: &str) -> Option<JClass>
FindClass, with an internal name like android/bluetooth/BluetoothAdapter.
Returns a local reference; promote it with
Env::new_global_ref to keep it past the current frame.
pub fn get_object_class(&self, object: JObject) -> JClass
pub fn method_id( &self, class: JClass, name: &str, signature: &str, ) -> Option<JMethodId>
pub fn static_method_id( &self, class: JClass, name: &str, signature: &str, ) -> Option<JMethodId>
pub fn static_field_id( &self, class: JClass, name: &str, signature: &str, ) -> Option<JFieldId>
pub fn static_object_field(&self, class: JClass, field: JFieldId) -> JObject
pub fn static_int_field(&self, class: JClass, field: JFieldId) -> i32
pub fn call_object( &self, object: JObject, method: JMethodId, args: &[JValue], ) -> JObject
pub fn call_bool( &self, object: JObject, method: JMethodId, args: &[JValue], ) -> bool
pub fn call_int( &self, object: JObject, method: JMethodId, args: &[JValue], ) -> i32
pub fn call_long( &self, object: JObject, method: JMethodId, args: &[JValue], ) -> i64
pub fn call_void(&self, object: JObject, method: JMethodId, args: &[JValue])
pub fn call_static_object( &self, class: JClass, method: JMethodId, args: &[JValue], ) -> JObject
pub fn call_static_int( &self, class: JClass, method: JMethodId, args: &[JValue], ) -> i32
pub fn call_static_void( &self, class: JClass, method: JMethodId, args: &[JValue], )
pub fn new_object( &self, class: JClass, ctor: JMethodId, args: &[JValue], ) -> JObject
Sourcepub fn alloc_object(&self, class: JClass) -> JObject
pub fn alloc_object(&self, class: JClass) -> JObject
Allocate without running a constructor.
pub fn new_global_ref(&self, object: JObject) -> JObject
pub fn delete_global_ref(&self, object: JObject)
pub fn delete_local_ref(&self, object: JObject)
pub fn is_same_object(&self, a: JObject, b: JObject) -> bool
Sourcepub fn push_local_frame(&self, capacity: i32) -> bool
pub fn push_local_frame(&self, capacity: i32) -> bool
Push a local frame, so a burst of locals is released together.
The default local-reference table is small — 512 entries on Android — and a scan callback that leaks a few per advertisement exhausts it.
pub fn pop_local_frame(&self)
pub fn new_string(&self, s: &str) -> JString
pub fn get_string(&self, string: JString) -> Option<String>
pub fn array_length(&self, array: JArray) -> i32
pub fn object_array_element(&self, array: JArray, index: i32) -> JObject
pub fn new_object_array( &self, length: i32, class: JClass, initial: JObject, ) -> JArray
pub fn set_object_array_element( &self, array: JArray, index: i32, value: JObject, )
Sourcepub fn new_byte_array(&self, data: &[u8]) -> JArray
pub fn new_byte_array(&self, data: &[u8]) -> JArray
Make a byte[] the VM owns.
Sourcepub fn register_natives(&self, class: JClass, methods: &[NativeMethod]) -> bool
pub fn register_natives(&self, class: JClass, methods: &[NativeMethod]) -> bool
Bind Rust functions to a class’s native methods.
Sourcepub fn new_direct_byte_buffer(&self, data: *mut u8, len: usize) -> JObject
pub fn new_direct_byte_buffer(&self, data: *mut u8, len: usize) -> JObject
Wrap memory we own as a java.nio.ByteBuffer the VM can read.
No copy is made, so the memory must outlive every use of the buffer — which for a DEX means the life of the class loader built from it.
pub fn exception_occurred(&self) -> JObject
pub fn exception_clear(&self)
pub fn exception_describe(&self)
pub fn throw_new(&self, class: JClass, message: &str)
Sourcepub fn check_exception(&self) -> bool
pub fn check_exception(&self) -> bool
Clear any pending exception.
A pending exception makes almost every later JNI call undefined, so every wrapper above clears before returning. The alternative — checking at each call site — is the same work done less reliably.