Sdk android api documentation

Android utility functions

Namespace: dmAndroid
Include: #include <dmsdk/dlib/android.h>
TYPES
OnActivityResult OnActivityResult callback typedef
OnActivityCreate OnActivityCreate callback typedef
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
void RegisterOnActivityResultListener( [type:dmAndroid::OnActivityResult]) register Android activity result callback
void UnregisterOnActivityResultListener( [type:dmAndroid::OnActivityResult]) unregister Android activity result callback
void RegisterOnActivityCreateListener( [type:dmAndroid::OnActivityCreate]) register Android onCreate callback
void UnregisterOnActivityCreateListener( [type:dmAndroid::OnActivityCreate]) unregister Android onCreate callback

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

RegisterOnActivityResultListener

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

Registers an activity result callback. Multiple listeners are allowed.

PARAMETERS

[type:dmAndroid::OnActivityResult] listener

UnregisterOnActivityResultListener

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

Unregisters an activity result callback

PARAMETERS

[type:dmAndroid::OnActivityResult] listener

RegisterOnActivityCreateListener

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

Registers an onCreate callback. Multiple listeners are allowed.

PARAMETERS

[type:dmAndroid::OnActivityCreate] listener

UnregisterOnActivityCreateListener

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

Unregisters an onCreate callback

PARAMETERS

[type:dmAndroid::OnActivityCreate] listener

Structs

ThreadAttacher

TYPE

class ThreadAttacher

Struct attaching the JNI environment. Detaches the


Types

OnActivityResult

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


OnActivityCreate

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