Class JNIExtensions
- Namespace
- Uralstech.UXR.QuestCamera
QOL extensions for the JNI.
public static class JNIExtensions
- Inheritance
-
objectJNIExtensions
Remarks
This class is public to allow package users to reuse these extensions if useful. However, it should not be considered stable and is not part of the supported public API. It exists solely as an internal utility and may change or be removed at any time.
Methods
JavaListAsManagedArray<T>(AndroidJavaObject)
Converts a java.util.List to a managed array.
public static T[] JavaListAsManagedArray<T>(this AndroidJavaObject current)
Parameters
currentAndroidJavaObject
Returns
- T[]
The converted array.
Type Parameters
TThe type of the elements.
Remarks
WARNING: This method DOES NOT verify if the native Java/Kotlin elements can actually be converted to the target type.
Supports converting elements to the types supported by ToManaged<T>(AndroidJavaObject) + AndroidJavaObject.
ToJava(object, Type)
Converts managed .NET/Unity object to a Java/Kotlin object represented by an AndroidJavaObject.
[SuppressMessage("Style", "IDE0046:Convert to conditional expression", Justification = "Code is neater without conditionals.")]
public static AndroidJavaObject ToJava(this object current, Type target)
Parameters
currentobjecttargetTypeThe type of the managed object.
Returns
- AndroidJavaObject
The converted Java object.
Remarks
Basic supported types:
- bool
- char
- sbyte
- short
- int
- long
- float
- double
- string
Supported Android types:
| Unity Type | Android Type |
|---|---|
| Resolution | android.util.Size |
| Rect | android.graphics.RectF |
| RectInt | android.graphics.Rect |
| CameraMetadata.IntRange | android.util.Range<Integer> |
| CameraMetadata.LongRange | android.util.Range<Long> |
| CameraMetadata.FloatRange | android.util.Range<Float> |
Also supports converting arrays of all above types + generic AndroidJavaObject[] and AndroidJavaProxy[].
Exceptions
- NotSupportedException
Thrown when the type is unsupported.
ToJava<T>(T)
Converts managed .NET/Unity object to a Java/Kotlin object represented by an AndroidJavaObject.
public static AndroidJavaObject ToJava<T>(this T current) where T : notnull
Parameters
currentT
Returns
- AndroidJavaObject
The converted Java object.
Type Parameters
TThe type of the managed object.
Remarks
Basic supported types:
- bool
- char
- sbyte
- short
- int
- long
- float
- double
- string
Supported Android types:
| Unity Type | Android Type |
|---|---|
| Resolution | android.util.Size |
| Rect | android.graphics.RectF |
| RectInt | android.graphics.Rect |
| CameraMetadata.IntRange | android.util.Range<Integer> |
| CameraMetadata.LongRange | android.util.Range<Long> |
| CameraMetadata.FloatRange | android.util.Range<Float> |
Also supports converting arrays of all above types + generic AndroidJavaObject[] and AndroidJavaProxy[].
Exceptions
- NotSupportedException
Thrown when the type is unsupported.
ToManaged(AndroidJavaObject, Type)
Converts a Java/Kotlin object represented by an AndroidJavaObject into a managed .NET/Unity type.
[SuppressMessage("Style", "IDE0046:Convert to conditional expression", Justification = "Code is neater without conditionals.")]
public static object ToManaged(this AndroidJavaObject current, Type target)
Parameters
currentAndroidJavaObjecttargetTypeThe managed target type.
Returns
- object
The converted managed object.
Remarks
WARNING: This method DOES NOT verify if the native Java/Kotlin object can actually be converted to the target type.
Basic supported types:
- bool
- char
- sbyte
- short
- int
- long
- float
- double
- string
Supported Android types:
| Unity Type | Android Type |
|---|---|
| Resolution | android.util.Size |
| Rect | android.graphics.RectF |
| RectInt | android.graphics.Rect |
| CameraMetadata.IntRange | android.util.Range<Integer> |
| CameraMetadata.LongRange | android.util.Range<Long> |
| CameraMetadata.FloatRange | android.util.Range<Float> |
Also supports converting arrays of all above types + generic AndroidJavaObject[].
Exceptions
- NotSupportedException
Thrown when the requested target type is unsupported.
ToManaged<T>(AndroidJavaObject)
public static T ToManaged<T>(this AndroidJavaObject current)
Parameters
currentAndroidJavaObject
Returns
- T
Type Parameters
TThe managed target type.
TryConvertToManaged<T>(AndroidJavaObject, out T?)
Safe version of ToManaged<T>(AndroidJavaObject).
public static bool TryConvertToManaged<T>(this AndroidJavaObject current, out T? value)
Parameters
currentAndroidJavaObjectvalueT
Returns
- bool
Type Parameters
T
UnboxBoolElement(nint, int)
Unboxes a boolean from a native Object array.
public static bool UnboxBoolElement(nint args, int index)
Parameters
argsnintThe native array to take the boolean from.
indexintThe index of the boolean object in the native array.
Returns
- bool
The unboxed boolean.
UnboxByteBufferElement(nint, int)
Retrieves a ByteBuffer object from a native object array and obtains its direct memory address.
public static (nint obj, nint ptr) UnboxByteBufferElement(nint args, int index)
Parameters
argsnintJNI object array containing the ByteBuffer.
indexintIndex of the ByteBuffer within the array.
Returns
- (nint obj, nint ptr)
A tuple containing the local JNI reference to the ByteBuffer, and the pointer to its direct buffer memory.
UnboxIntElement(nint, int)
Unboxes an integer from a native Object array.
public static int UnboxIntElement(nint args, int index)
Parameters
argsnintThe native array to take the integer from.
indexintThe index of the integer object in the native array.
Returns
- int
The unboxed integer.
UnboxLongElement(nint, int)
Unboxes a long from a native Object array.
public static long UnboxLongElement(nint args, int index)
Parameters
argsnintThe native array to take the long from.
indexintThe index of the long object in the native array.
Returns
- long
The unboxed long.
UnboxObjectElement(nint, int)
Unboxes an AndroidJavaObject from a native Object array.
public static AndroidJavaObject UnboxObjectElement(nint args, int index)
Parameters
argsnintThe native array to take the object from.
indexintThe index of the object in the native array.
Returns
- AndroidJavaObject
The unboxed object.