I found an example a long time ago to show/hide the input keyboard; I modified that to just call the class in MyNativeActivity extends NativeActivity ... the original was more complex than this.... this way simplifies it kinda
{
public void setSuspendSleep() {
this.runOnUiThread( new Runnable() {
public void run()
{
getWindow().addFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON );
}
} );
}
public void setAllowSleep() {
this.runOnUiThread( new Runnable() {
public void run() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
} );
}
}
------- and then in C++ ------
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
extern "C" void SuspendSleep( int bStopSleep )
{
static int init;
static jobject WindowManager_LayoutParams_FLAG_KEEP_SCREEN_ON;
// Attaches the current thread to the JVM.
jint lResult;
jint lFlags = 0;
JavaVM* lJavaVM = engine.app->activity->vm;
JNIEnv* lJNIEnv = engine.app->activity->env;
JavaVMAttachArgs lJavaVMAttachArgs;
lJavaVMAttachArgs.version = JNI_VERSION_1_6;
lJavaVMAttachArgs.name = "NativeThread";
lJavaVMAttachArgs.group = NULL;
lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs);
if (lResult == JNI_ERR) {
return;
}
// Retrieves NativeActivity.
jobject lNativeActivity = engine.app->activity->clazz;
jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity);
if( bStopSleep )
{
jmethodID MethodSetFlags = lJNIEnv->GetMethodID( ClassNativeActivity, "setSuspendSleep", "()V");
if( MethodSetFlags )
lJNIEnv->CallVoidMethod( lNativeActivity, MethodSetFlags );
}
else
{
jmethodID MethodSetFlags = lJNIEnv->GetMethodID( ClassNativeActivity, "setAllowSleep", "()V");
if( MethodSetFlags )
lJNIEnv->CallVoidMethod( lNativeActivity, MethodSetFlags );
}
// Finished with the JVM.
lJavaVM->DetachCurrentThread();
}