Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


AndroidJNI

'Raw' JNI interface to Android Java VM from Unity scripting (C#). Note: Using raw JNI functions requires advanced knowledge of the Android Java Native Interface (JNI). Please take note.
Read time 17 minutesLast updated 4 days ago

Definition

  • Type: Class
  • Namespace: UnityEngine
  • Assembly: UnityEngine.AndroidJNIModule
public static class AndroidJNI

Static Methods

Method

Description

AllocObjectAllocates a new Java object without invoking any of the constructors for the object.
AttachCurrentThreadAttaches the current thread to a Java (Dalvik) VM.
CallBooleanMethodCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallBooleanMethodUnsafeCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallCharMethodCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallCharMethodUnsafeCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallDoubleMethodCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallDoubleMethodUnsafeCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallFloatMethodCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallFloatMethodUnsafeCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallIntMethodCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallIntMethodUnsafeCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallLongMethodCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallLongMethodUnsafeCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallObjectMethodCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallObjectMethodUnsafeCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallSByteMethodCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallSByteMethodUnsafeCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallShortMethodCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallShortMethodUnsafeCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallStaticBooleanMethodInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticBooleanMethodUnsafeInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticCharMethodInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticCharMethodUnsafeInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticDoubleMethodInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticDoubleMethodUnsafeInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticFloatMethodInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticFloatMethodUnsafeInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticIntMethodInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticIntMethodUnsafeInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticLongMethodInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticLongMethodUnsafeInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticObjectMethodInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticObjectMethodUnsafeInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticSByteMethodInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticSByteMethodUnsafeInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticShortMethodInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticShortMethodUnsafeInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticStringMethodInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticStringMethodUnsafeInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticVoidMethodInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStaticVoidMethodUnsafeInvokes the specified \<tt\>methodID\</tt\> static method on a Java object, optionally passing in an array of arguments (\<tt\>args\</tt\>).
CallStringMethodCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallStringMethodUnsafeCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallVoidMethodCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
CallVoidMethodUnsafeCalls a Java instance method defined by \<tt\>methodID\</tt\>, optionally passing an array of arguments (\<tt\>args\</tt\>) to the method.
DeleteGlobalRefDeletes the global reference pointed to by \<tt\>obj\</tt\>.
DeleteLocalRefDeletes the local reference pointed to by \<tt\>obj\</tt\>.
DeleteWeakGlobalRefDeletes the global weak reference pointed to by \<tt\>obj\</tt\>.
DetachCurrentThreadDetaches the current thread from a Java (Dalvik) VM.
EnsureLocalCapacityEnsures that at least a given number of local references can be created in the current thread.
ExceptionClearClears any exception that is currently being thrown.
ExceptionDescribePrints an exception and a backtrace of the stack to the \<tt\>logcat\</tt\>
ExceptionOccurredDetermines if an exception is being thrown.
FatalErrorRaises a fatal error and does not expect the VM to recover. This function does not return.
FindClassThis function loads a locally-defined class.
FromBooleanArrayConverts a Java array of \<tt\>boolean\</tt\> to a managed array of System.Boolean.
FromCharArrayConverts a Java array of \<tt\>char\</tt\> to a managed array of System.Char.
FromDoubleArrayConverts a Java array of \<tt\>double\</tt\> to a managed array of System.Double.
FromFloatArrayConverts a Java array of \<tt\>float\</tt\> to a managed array of System.Single.
FromIntArrayConverts a Java array of \<tt\>int\</tt\> to a managed array of System.Int32.
FromLongArrayConverts a Java array of \<tt\>long\</tt\> to a managed array of System.Int64.
FromObjectArrayConverts a Java array of \<tt\>java.lang.Object\</tt\> to a managed array of System.IntPtr, representing Java objects.
FromReflectedFieldConverts a \<tt\>java.lang.reflect.Field\</tt\> to a field ID.
FromReflectedMethodConverts a \<tt\>java.lang.reflect.Method\</tt\> or \<tt\>java.lang.reflect.Constructor\</tt\> object to a method ID.
FromSByteArrayConverts a Java array of \<tt\>byte\</tt\> to a managed array of System.SByte.
FromShortArrayConverts a Java array of \<tt\>short\</tt\> to a managed array of System.Int16.
GetArrayLengthReturns the number of elements in the array.
GetBooleanArrayElementReturns the value of one element of a primitive array.
GetBooleanFieldReturns the value of an instance (nonstatic) field of an object.
GetCharArrayElementReturns the value of one element of a primitive array.
GetCharFieldReturns the value of an instance (nonstatic) field of an object.
GetDirectBufferAddressFetches and returns the starting address of the memory region referenced by the given direct java.nio.Buffer.
GetDirectBufferCapacityFetches and returns the capacity of the memory region referenced by the given direct java.nio.Buffer.
GetDirectByteBufferReturns the NativeArray backed by the same memory region as the given direct java.nio.Buffer.
GetDirectSByteBufferReturns the NativeArray backed by the same memory region as the given direct java.nio.Buffer.
GetDoubleArrayElementReturns the value of one element of a primitive array.
GetDoubleFieldReturns the value of an instance (nonstatic) field of an object.
GetFieldIDReturns the field ID for an instance (nonstatic) field of a class.
GetFloatArrayElementReturns the value of one element of a primitive array.
GetFloatFieldReturns the value of an instance (nonstatic) field of an object.
GetIntArrayElementReturns the value of one element of a primitive array.
GetIntFieldReturns the value of an instance (nonstatic) field of an object.
GetJavaVMReturns the pointer to JavaVM.
GetLongArrayElementReturns the value of one element of a primitive array.
GetLongFieldReturns the value of an instance (nonstatic) field of an object.
GetMethodIDReturns the method ID for an instance (nonstatic) method of a class or interface.
GetObjectArrayElementReturns an element of an \<tt\>Object\</tt\> array.
GetObjectClassReturns the class of an object.
GetObjectFieldReturns the value of an instance (nonstatic) field of an object.
GetSByteArrayElementReturns the value of one element of a primitive array.
GetSByteFieldReturns the value of an instance (nonstatic) field of an object.
GetShortArrayElementReturns the value of one element of a primitive array.
GetShortFieldReturns the value of an instance (nonstatic) field of an object.
GetStaticBooleanFieldReturns the value of a static field of an object.
GetStaticCharFieldReturns the value of a static field of an object.
GetStaticDoubleFieldReturns the value of a static field of an object.
GetStaticFieldIDReturns the field ID for a static field of a class.
GetStaticFloatFieldReturns the value of a static field of an object.
GetStaticIntFieldReturns the value of a static field of an object.
GetStaticLongFieldReturns the value of a static field of an object.
GetStaticMethodIDReturns the method ID for a static method of a class.
GetStaticObjectFieldReturns the value of a static field of an object.
GetStaticSByteFieldReturns the value of a static field of an object.
GetStaticShortFieldReturns the value of a static field of an object.
GetStaticStringFieldReturns the value of a static field of an object.
GetStringCharsReturns a pointer to the array of Unicode characters of the string. This pointer is valid until ReleaseStringchars() is called.
GetStringFieldReturns the value of an instance (nonstatic) field of an object.
GetStringLengthReturns the length (the count of Unicode characters) of a Java string.
GetStringUTFCharsReturns a managed string object representing the string in modified UTF-8 encoding.
GetStringUTFLengthReturns the length in bytes of the modified UTF-8 representation of a string.
GetSuperclassIf \<tt\>clazz\</tt\> represents any class other than the class \<tt\>Object\</tt\>, then this function returns the object that represents the superclass of the class specified by \<tt\>clazz\</tt\>.
GetVersionReturns the version of the native method interface.
InvokeAttachedCalls AndroidJNI.AttachCurrentThread (if necessary) before invoking a delegate, and then calls AndroidJNI.DetachCurrentThread.
IsAssignableFromDetermines whether an object of \<tt\>clazz1\</tt\> can be safely cast to \<tt\>clazz2\</tt\>.
IsInstanceOfTests whether an object is an instance of a class.
IsSameObjectTests whether two references refer to the same Java object.
NewBooleanArrayConstructs a new primitive array object.
NewCharArrayConstructs a new primitive array object.
NewDirectByteBufferAllocates and returns a direct java.nio.ByteBuffer referring to the block of memory starting at the memory address address and extending capacity bytes.
NewDoubleArrayConstructs a new primitive array object.
NewFloatArrayConstructs a new primitive array object.
NewGlobalRefCreates a new global reference to the object referred to by the \<tt\>obj\</tt\> argument.
NewIntArrayConstructs a new primitive array object.
NewLocalRefCreates a new local reference that refers to the same object as \<tt\>obj\</tt\>.
NewLongArrayConstructs a new primitive array object.
NewObjectConstructs a new Java object. The method ID indicates which constructor method to invoke. This ID must be obtained by calling GetMethodID() with \<init\> as the method name and void (V) as the return type.
NewObjectAConstructs a new Java object. The method ID indicates which constructor method to invoke. This ID must be obtained by calling GetMethodID() with \<init\> as the method name and void (V) as the return type.
NewObjectArrayConstructs a new array holding objects in class \<tt\>clazz\</tt\>. All elements are initially set to \<tt\>obj\</tt\>.
NewSByteArrayConstructs a new primitive array object.
NewShortArrayConstructs a new primitive array object.
NewStringConstructs a new \<tt\>java.lang.String\</tt\> object from an array of Unicode characters.
NewStringUTFConstructs a new \<tt\>java.lang.String\</tt\> object from an array of characters in modified UTF-8 encoding.
NewWeakGlobalRefCreates a new global weak reference to the object referred to by the \<tt\>obj\</tt\> argument.
PopLocalFramePops off the current local reference frame, frees all the local references, and returns a local reference in the previous local reference frame for the given \<tt\>result\</tt\> object.
PushLocalFrameCreates a new local reference frame, in which at least a given number of local references can be created.
RegisterNativesRegisters native methods with the class specified by the clazz argument.
SetBooleanArrayElementSets the boolean value of one element in a primitive array.
SetBooleanFieldSets the value of an instance field of the specified object.
SetCharArrayElementSets the char value of one element in a primitive array.
SetCharFieldSets the value of an instance field of the specified object.
SetDoubleArrayElementSets the double value of one element in a primitive array.
SetDoubleFieldSets the value of an instance field of the specified object.
SetFloatArrayElementSets the float value of one element in a primitive array.
SetFloatFieldSets the value of an instance field of the specified object.
SetIntArrayElementSets the int value of one element in a primitive array.
SetIntFieldSets the value of an instance field of the specified object.
SetLongArrayElementSets the long value of one element in a primitive array.
SetLongFieldSets the value of an instance field of the specified object.
SetObjectArrayElementSets an element of an \<tt\>Object\</tt\> array.
SetObjectFieldSets the value of an instance field of the specified object.
SetSByteArrayElementSets the sbyte value of one element in a primitive array.
SetSByteFieldSets the value of an instance field of the specified object.
SetShortArrayElementSets the short value of one element in a primitive array.
SetShortFieldSets the value of an instance field of the specified object.
SetStaticBooleanFieldSets the value of a static field in the specified object.
SetStaticCharFieldSets the value of a static field in the specified object.
SetStaticDoubleFieldSets the value of a static field in the specified object.
SetStaticFloatFieldSets the value of a static field in the specified object.
SetStaticIntFieldSets the value of a static field in the specified object.
SetStaticLongFieldSets the value of a static field in the specified object.
SetStaticObjectFieldSets the value of a static field in the specified object.
SetStaticSByteFieldSets the value of a static field in the specified object.
SetStaticShortFieldSets the value of a static field in the specified object.
SetStaticStringFieldSets the value of a static field in the specified object.
SetStringFieldSets the value of an instance field of the specified object.
ThrowCauses a \<tt\>java.lang.Throwable\</tt\> object to be thrown.
ThrowNewConstructs an exception object from the specified class with the \<tt\>message\</tt\> specified by message and causes that exception to be thrown.
ToBooleanArrayConverts a managed array of System.Boolean to a Java array of \<tt\>boolean\</tt\>.
ToCharArrayConverts a managed array of System.Char to a Java array of \<tt\>char\</tt\>.
ToDoubleArrayConverts a managed array of System.Double to a Java array of \<tt\>double\</tt\>.
ToFloatArrayConverts a managed array of System.Single to a Java array of \<tt\>float\</tt\>.
ToIntArrayConverts a managed array of System.Int32 to a Java array of \<tt\>int\</tt\>.
ToLongArrayConverts a managed array of System.Int64 to a Java array of \<tt\>long\</tt\>.
ToObjectArrayConverts a managed array of System.IntPtr, representing Java objects, to a Java array of \<tt\>java.lang.Object\</tt\>.
ToReflectedFieldConverts a field ID derived from cls to a \<tt\>java.lang.reflect.Field\</tt\> object.
ToReflectedMethodConverts a method ID derived from clazz to a \<tt\>java.lang.reflect.Method\</tt\> or \<tt\>java.lang.reflect.Constructor\</tt\> object.
ToSByteArrayConverts a managed array of System.SByte to a Java array of \<tt\>byte\</tt\>.
ToShortArrayConverts a managed array of System.Int16 to a Java array of \<tt\>short\</tt\>.
UnregisterNativesUnregisters native methods of a class. The class goes back to the state before it was linked or registered with its native method functions.