@@ -480,3 +480,25 @@ char* listURI(uintptr_t jni_env, uintptr_t ctx, char* uriCstr) {
480
480
LOG_FATAL ("Unrecognized scheme: %s" , uriCstr );
481
481
return "" ;
482
482
}
483
+
484
+ void keepScreenOn (uintptr_t jni_env , uintptr_t ctx , bool disabled ) {
485
+ JNIEnv * env = (JNIEnv * )jni_env ;
486
+ jclass activityClass = find_class (env , "android/app/Activity" );
487
+ jmethodID getWindow = find_method (env , activityClass , "getWindow" , "()Landroid/view/Window;" );
488
+
489
+ jobject win = (* env )-> CallObjectMethod (env , (jobject )ctx , getWindow );
490
+ jclass windowClass = find_class (env , "android/view/Window" );
491
+
492
+ jmethodID action = NULL ;
493
+ if (disabled ) {
494
+ action = find_method (env , windowClass , "addFlags" , "(I)V" );
495
+ } else {
496
+ action = find_method (env , windowClass , "clearFlags" , "(I)V" );
497
+ }
498
+
499
+ jclass paramsClass = find_class (env , "android/view/WindowManager$LayoutParams" );
500
+ jfieldID screenFlagField = (* env )-> GetStaticFieldID (env , paramsClass , "FLAG_KEEP_SCREEN_ON" , "I" );
501
+ int screenFlag = (* env )-> GetStaticIntField (env , paramsClass , screenFlagField );
502
+
503
+ (* env )-> CallVoidMethod (env , win , action , screenFlag );
504
+ }
0 commit comments