Sdk android api documentation

Android utility functions

Namespace: dmAndroid
Include: #include <dmsdk/dlib/android.h>
STRUCTS
class ThreadAttacher Struct attaching the JNI environment. Detaches the
FUNCTIONS
void ThreadAttacher() constructor
bool Detach() Detaches the jni environment
bool IsAttached() Is the environment attached and valid?
JNIENV* GetEnv() Gets the JNI environment
ANativeActivity* GetActivity() Gets the app native activity
jclass LoadClass() Load a class

Functions

ThreadAttacher

void ThreadAttacher()

constructor

PARAMETERS

EXAMPLES

{
  ThreadAttacher thread;
  SomeFunction( thread.GetEnv() );
  // Automatically detaches
}
{
  ThreadAttacher thread;
  JNIEnv* env = thread.GetEnv();
  if (!env)
    return;
  ...
}

Detach

bool Detach()

Detaches the jni environment

PARAMETERS

RETURNS

bool true if there was no java exceptions. False if there was an exception.

IsAttached

bool IsAttached()

Is the environment attached and valid?

PARAMETERS

RETURNS

bool true if the environment is valid

EXAMPLES

Result SomeFunc() {
  ThreadAttacher thread;
  JNIEnv* env = thread.GetEnv();
  if (!env)
    return RESULT_ATTACH_FAILED;
  ... calls using jni
  return thread.Detach() ? RESULT_OK : RESULT_JNI_CALLS_FAILED;
}

GetEnv

JNIENV* GetEnv()

Gets the JNI environment

PARAMETERS

RETURNS

JNIENV* the attached environment

GetActivity

ANativeActivity* GetActivity()

Gets the app native activity

PARAMETERS

RETURNS

ANativeActivity* the app native activity

LoadClass

jclass LoadClass()

Load a class

PARAMETERS

RETURNS

jclass the activity class loader

Structs

ThreadAttacher

TYPE

class ThreadAttacher

Struct attaching the JNI environment. Detaches the