Sdk android api documentation

Android utility functions

Namespace: dmAndroid
Include: #include <dmsdk/dlib/android.h>
TYPES
OnActivityCreate OnActivityCreate callback typedef
OnActivityResult OnActivityResult callback typedef
STRUCTS
class ThreadAttacher Struct attaching the JNI environment. Detaches the
FUNCTIONS
bool Detach() Detaches the jni environment
ANativeActivity* GetActivity() Gets the app native activity
JNIENV* GetEnv() Gets the JNI environment
bool IsAttached() Is the environment attached and valid?
jclass LoadClass(JNIEnv* env, const char* class_name) Load a class
jclass LoadClass(JNIEnv* env, jobject activity, const char* class_name) Load a class
void RegisterOnActivityCreateListener( [type:dmAndroid::OnActivityCreate]) register Android onCreate callback
void RegisterOnActivityResultListener( [type:dmAndroid::OnActivityResult]) register Android activity result callback
void ThreadAttacher() constructor
void UnregisterOnActivityCreateListener( [type:dmAndroid::OnActivityCreate]) unregister Android onCreate callback
void UnregisterOnActivityResultListener( [type:dmAndroid::OnActivityResult]) unregister Android activity result callback

Functions

Detach

bool Detach()

Detaches the jni environment

PARAMETERS

RETURNS

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

GetActivity

ANativeActivity* GetActivity()

Gets the app native activity

PARAMETERS

RETURNS

ANativeActivity* the app native activity

GetEnv

JNIENV* GetEnv()

Gets the JNI environment

PARAMETERS

RETURNS

JNIENV* the attached environment

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;
}

LoadClass

jclass LoadClass(JNIEnv* env, const char* class_name)

Load a class

PARAMETERS

JNIEnv* env
const char* class_name

RETURNS

jclass the activity class loader

LoadClass

jclass LoadClass(JNIEnv* env, jobject activity, const char* class_name)

Load a class

PARAMETERS

JNIEnv* env
jobject activity
const char* class_name

RETURNS

jclass the activity class loader

RegisterOnActivityCreateListener

void RegisterOnActivityCreateListener( [type:dmAndroid::OnActivityCreate])

Registers an onCreate callback. Multiple listeners are allowed.

PARAMETERS

[type:dmAndroid::OnActivityCreate] listener

RegisterOnActivityResultListener

void RegisterOnActivityResultListener( [type:dmAndroid::OnActivityResult])

Registers an activity result callback. Multiple listeners are allowed.

PARAMETERS

[type:dmAndroid::OnActivityResult] listener

ThreadAttacher

void ThreadAttacher()

constructor

PARAMETERS

EXAMPLES

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

UnregisterOnActivityCreateListener

void UnregisterOnActivityCreateListener( [type:dmAndroid::OnActivityCreate])

Unregisters an onCreate callback

PARAMETERS

[type:dmAndroid::OnActivityCreate] listener

UnregisterOnActivityResultListener

void UnregisterOnActivityResultListener( [type:dmAndroid::OnActivityResult])

Unregisters an activity result callback

PARAMETERS

[type:dmAndroid::OnActivityResult] listener

Structs

ThreadAttacher

TYPE

class ThreadAttacher

Struct attaching the JNI environment. Detaches the


Types

OnActivityCreate

onCreate callback function type. Used with RegisterOnActivityCreateListener() and UnregisterOnActivityCreateListener()


OnActivityResult

Activity result callback function type. Monitors events from the main activity. Used with RegisterOnActivityResultListener() and UnregisterOnActivityResultListener()