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 |
bool Detach()
Detaches the jni environment
PARAMETERS
RETURNS
bool |
true if there was no java exceptions. False if there was an exception. |
ANativeActivity* GetActivity()
Gets the app native activity
PARAMETERS
RETURNS
ANativeActivity* |
the app native activity |
JNIENV* GetEnv()
Gets the JNI environment
PARAMETERS
RETURNS
JNIENV* |
the attached environment |
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;
}
jclass LoadClass(JNIEnv* env, const char* class_name)
Load a class
PARAMETERS
JNIEnv* |
env |
|
const char* |
class_name |
RETURNS
jclass |
the activity class loader |
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 |
void RegisterOnActivityCreateListener( [type:dmAndroid::OnActivityCreate])
Registers an onCreate callback. Multiple listeners are allowed.
PARAMETERS
|
[type:dmAndroid::OnActivityCreate] |
listener |
void RegisterOnActivityResultListener( [type:dmAndroid::OnActivityResult])
Registers an activity result callback. Multiple listeners are allowed.
PARAMETERS
|
[type:dmAndroid::OnActivityResult] |
listener |
void ThreadAttacher()
constructor
PARAMETERS
EXAMPLES
{
ThreadAttacher thread;
SomeFunction( thread.GetEnv() );
// Automatically detaches
}
{
ThreadAttacher thread;
JNIEnv* env = thread.GetEnv();
if (!env)
return;
...
}
void UnregisterOnActivityCreateListener( [type:dmAndroid::OnActivityCreate])
Unregisters an onCreate callback
PARAMETERS
|
[type:dmAndroid::OnActivityCreate] |
listener |
void UnregisterOnActivityResultListener( [type:dmAndroid::OnActivityResult])
Unregisters an activity result callback
PARAMETERS
|
[type:dmAndroid::OnActivityResult] |
listener |
TYPE
class ThreadAttacher
Struct attaching the JNI environment. Detaches the
onCreate callback function type. Used with RegisterOnActivityCreateListener() and UnregisterOnActivityCreateListener()
Activity result callback function type. Monitors events from the main activity. Used with RegisterOnActivityResultListener() and UnregisterOnActivityResultListener()