Documentation ¶
Overview ¶
Package jni implements various helper functions for communicating with the Android JVM though JNI.
Index ¶
- Constants
- func CallBooleanMethod(e Env, obj Object, method MethodID, args ...Value) (bool, error)
- func CallByteMethod(e Env, obj Object, method MethodID, args ...Value) (byte, error)
- func CallCharMethod(e Env, obj Object, method MethodID, args ...Value) (rune, error)
- func CallDoubleMethod(e Env, obj Object, method MethodID, args ...Value) (float64, error)
- func CallFloatMethod(e Env, obj Object, method MethodID, args ...Value) (float32, error)
- func CallIntMethod(e Env, obj Object, method MethodID, args ...Value) (int32, error)
- func CallLongMethod(e Env, obj Object, method MethodID, args ...Value) (int64, error)
- func CallShortMethod(e Env, obj Object, method MethodID, args ...Value) (int16, error)
- func CallStaticBooleanMethod(e Env, cls Class, method MethodID, args ...Value) (bool, error)
- func CallStaticIntMethod(e Env, cls Class, method MethodID, args ...Value) (int, error)
- func CallStaticVoidMethod(e Env, cls Class, method MethodID, args ...Value) error
- func CallVoidMethod(e Env, obj Object, method MethodID, args ...Value) error
- func DeleteGlobalRef(e Env, obj Object)
- func DeleteLocalRef(e Env, obj Object)
- func Do(vm JVM, f func(env Env) error) error
- func GetBooleanField(env Env, obj Object, fieldID FieldID) bool
- func GetByteArrayElements(e Env, jarr ByteArray) []byte
- func GetByteField(env Env, obj Object, fieldID FieldID) byte
- func GetCharField(env Env, obj Object, fieldID FieldID) byte
- func GetDoubleField(env Env, obj Object, fieldID FieldID) float64
- func GetFloatField(env Env, obj Object, fieldID FieldID) float32
- func GetIntField(env Env, obj Object, fieldID FieldID) int32
- func GetLongField(env Env, obj Object, fieldID FieldID) int64
- func GetShortField(env Env, obj Object, fieldID FieldID) int16
- func GetStaticBooleanField(env Env, clazz Class, fieldID FieldID) bool
- func GetStaticByteField(env Env, clazz Class, fieldID FieldID) byte
- func GetStaticCharField(env Env, clazz Class, fieldID FieldID) byte
- func GetStaticDoubleField(env Env, clazz Class, fieldID FieldID) float64
- func GetStaticFloatField(env Env, clazz Class, fieldID FieldID) float32
- func GetStaticIntField(env Env, clazz Class, fieldID FieldID) int32
- func GetStaticLongField(env Env, clazz Class, fieldID FieldID) int64
- func GetStaticShortField(env Env, clazz Class, fieldID FieldID) int16
- func GoString(e Env, str String) string
- func IsInstanceOf(e Env, obj Object, cls Class) bool
- func IsSameObject(e Env, ref1, ref2 Object) bool
- func SetObjectArrayElement(e Env, jarr ObjectArray, index Size, value Object) error
- type ByteArray
- type Class
- type Env
- type FieldID
- type JVM
- type MethodID
- type Object
- func CallObjectMethod(e Env, obj Object, method MethodID, args ...Value) (Object, error)
- func CallStaticObjectMethod(e Env, cls Class, method MethodID, args ...Value) (Object, error)
- func ClassLoaderFor(e Env, obj Object) Object
- func GetObjectArrayElement(e Env, jarr ObjectArray, index Size) (Object, error)
- func GetObjectField(env Env, obj Object, fieldID FieldID) Object
- func GetStaticObjectField(env Env, clazz Class, fieldID FieldID) Object
- func NewGlobalRef(e Env, obj Object) Object
- func NewLocalRef(e Env, obj Object) Object
- func NewObject(e Env, cls Class, method MethodID, args ...Value) (Object, error)
- type ObjectArray
- type Size
- type String
- type Value
Constants ¶
const ( TRUE = C.JNI_TRUE FALSE = C.JNI_FALSE )
Variables ¶
This section is empty.
Functions ¶
func CallBooleanMethod ¶
CallBooleanMethod calls a method on an object, returning a bool.
func CallByteMethod ¶
CallByteMethod calls a method on an object, returning a byte.
func CallCharMethod ¶
CallCharMethod calls a method on an object, returning a rune.
func CallDoubleMethod ¶
CallDoubleMethod calls a method on an object, returning a float64.
func CallFloatMethod ¶
CallFloatMethod calls a method on an object, returning a float32.
func CallIntMethod ¶
CallIntMethod calls a method on an object, returning an int32.
func CallLongMethod ¶
CallLongMethod calls a method on an object, returning an int64.
func CallShortMethod ¶
CallShortMethod calls a method on an object, returning an int32.
func CallStaticBooleanMethod ¶
CallStaticBooleanMethod calls a static method on a Java class, returning an int.
func CallStaticIntMethod ¶
CallStaticIntMethod calls a static method on a Java class, returning an int.
func CallStaticVoidMethod ¶
CallStaticVoidMethod calls a static method on a Java class, returning nothing.
func CallVoidMethod ¶
CallVoidMethod calls a method on an object, returning nothing.
func DeleteGlobalRef ¶
DeleteGlobalRef delets a global reference.
func DeleteLocalRef ¶
DeleteLocalRef delets a local reference.
func Do ¶
Do invokes a function with a temporary JVM environment. The environment is not valid after the function returns.
func GetBooleanField ¶
GetBooleanField looks up the value of a static field of type boolean. This should never throw an exception.
func GetByteArrayElements ¶
GetByteArrayElements returns the contents of the array.
func GetByteField ¶
GetByteField looks up the value of a static field of type byte. This should never throw an exception.
func GetCharField ¶
GetCharField looks up the value of a static field of type char. This should never throw an exception.
func GetDoubleField ¶
GetDoubleField looks up the value of a static field of type double. This should never throw an exception.
func GetFloatField ¶
GetFloatField looks up the value of a static field of type float. This should never throw an exception.
func GetIntField ¶
GetIntField looks up the value of a static field of type int. This should never throw an exception.
func GetLongField ¶
GetLongField looks up the value of a static field of type long. This should never throw an exception.
func GetShortField ¶
GetShortField looks up the value of a static field of type short. This should never throw an exception.
func GetStaticBooleanField ¶
GetStaticBooleanField looks up the value of a static field of type boolean. This should never throw an exception.
func GetStaticByteField ¶
GetStaticByteField looks up the value of a static field of type byte. This should never throw an exception.
func GetStaticCharField ¶
GetStaticCharField looks up the value of a static field of type char. This should never throw an exception.
func GetStaticDoubleField ¶
GetStaticDoubleField looks up the value of a static field of type double. This should never throw an exception.
func GetStaticFloatField ¶
GetStaticFloatField looks up the value of a static field of type float. This should never throw an exception.
func GetStaticIntField ¶
GetStaticIntField looks up the value of a static field of type int. This should never throw an exception.
func GetStaticLongField ¶
GetStaticLongField looks up the value of a static field of type long. This should never throw an exception.
func GetStaticShortField ¶
GetStaticShortField looks up the value of a static field of type short. This should never throw an exception.
func IsInstanceOf ¶
IsInstanceOf returns true if the given object is an instance of the given class.
func IsSameObject ¶
IsSameObject returns true if the two given objects refer to the same Java object.
func SetObjectArrayElement ¶
func SetObjectArrayElement(e Env, jarr ObjectArray, index Size, value Object) error
Types ¶
type ByteArray ¶
type ByteArray C.jbyteArray
func NewByteArray ¶
NewByteArray allocates a Java byte array with the content. It panics if the allocation fails.
type Class ¶
func FindClass ¶
FindClass returns a reference to a Java class with a given name, using the JVM's default class loader. Any exceptions caused by the underlying JNI call (for example if the class is not found) will result in a panic.
func GetObjectClass ¶
GetObjectClass returns the Java Class for an Object.
type FieldID ¶
func GetFieldID ¶
GetFieldID returns the id for a field. It panics if the field wasn't found.
type JVM ¶
type JVM struct {
// contains filtered or unexported fields
}
func CreateJavaVM ¶
func CreateJavaVM() JVM
CreateJavaVM creates a new Java VM with the options specified (if any). This should not be called more than once as it can result in an error if a JVM already exists for a given process.
This is not implemented on Android and is therefore excluded on that platform by build flags and C.
type MethodID ¶
func GetMethodID ¶
GetMethodID returns the id for a method. It panics if the method wasn't found.
type Object ¶
func CallObjectMethod ¶
CallObjectMethod calls a method on an object, returning a Java object.
func CallStaticObjectMethod ¶
CallStaticObjectMethod calls a static method on a class, returning a Java object
func ClassLoaderFor ¶
ClassLoader returns a reference to the Java ClassLoader associated with obj.
func GetObjectArrayElement ¶
func GetObjectArrayElement(e Env, jarr ObjectArray, index Size) (Object, error)
func GetObjectField ¶
GetObjectField looks up the value of a static field of type Object. This should never throw an exception.
func GetStaticObjectField ¶
GetStaticObjectField looks up the value of a static field of type Object. This should never throw an exception.
func NewGlobalRef ¶
NewGlobalRef creates a new global reference.
func NewLocalRef ¶
NewLocalRef creates a new local reference to the given object.
type ObjectArray ¶
type ObjectArray C.jobjectArray
func NewObjectArray ¶
func NewObjectArray(e Env, len Size, class Class, elem Object) ObjectArray
type String ¶
func JavaString ¶
JavaString converts the string to a JVM jstring.