How to disable screensaver on Qt6.9.1 Android App
-
I found this bit of java which I think does what I want:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
wl.acquire();
...
// screen and CPU will stay awake during this section
...
wl.release();Can this be used with QJniObject class if so how do I do it ?
@SMF-Qt
Having read some Qt5 solutions for this problem, and the associated Android devlopment and Qt6 Jni information I have come up with this solution for setting the screen in Landscape mode and stopping the screen timeout.The landscape bit works but the screen lock only seems to work on the simulator.
The code is running through the appropriate path in all cases as indicated by the flags a,b,c,d which I display on the screen of my app (all 1's) as a debug aid:Sorry for using a png image but the stupid spam filter would not let me post the actual code!!!!
Can anyone see any mistakes in what I have written that stop it working on real hardware (could it be a permissions issue)?
-
@SMF-Qt
Having read some Qt5 solutions for this problem, and the associated Android devlopment and Qt6 Jni information I have come up with this solution for setting the screen in Landscape mode and stopping the screen timeout.The landscape bit works but the screen lock only seems to work on the simulator.
The code is running through the appropriate path in all cases as indicated by the flags a,b,c,d which I display on the screen of my app (all 1's) as a debug aid:Sorry for using a png image but the stupid spam filter would not let me post the actual code!!!!
Can anyone see any mistakes in what I have written that stop it working on real hardware (could it be a permissions issue)?
Added a line of code to try and address any permission issues, but this was ineffectual:
int a=0,b=0,c=0,d=0; QFuture permission_request = QtAndroidPrivate::requestPermission("android.permission.SCREEN_DIM_WAKE_LOCK"); // new code QJniObject wakeLock;
-
Added a line of code to try and address any permission issues, but this was ineffectual:
int a=0,b=0,c=0,d=0; QFuture permission_request = QtAndroidPrivate::requestPermission("android.permission.SCREEN_DIM_WAKE_LOCK"); // new code QJniObject wakeLock;
Someone suggested this solution but again the isValid() tests pass but the result fails.
#ifdef ANDROID int a=0,b=0,c=0,d=0; QJniObject window; QJniObject activity = QNativeInterface::QAndroidApplication::context(); if(activity.isValid()) { a=1; activity.callMethod<void>("setRequestedOrientation", "(I)V", 0); window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;"); if (window.isValid()) { b=1; window.callMethod<void>("addFlags", "(I)V","WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)"); } } #endif
-
Hi everyone. I'm new here out of curiosity.
I don't know if I can be of any help, but try asking Grok. -
Someone suggested this solution but again the isValid() tests pass but the result fails.
#ifdef ANDROID int a=0,b=0,c=0,d=0; QJniObject window; QJniObject activity = QNativeInterface::QAndroidApplication::context(); if(activity.isValid()) { a=1; activity.callMethod<void>("setRequestedOrientation", "(I)V", 0); window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;"); if (window.isValid()) { b=1; window.callMethod<void>("addFlags", "(I)V","WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)"); } } #endif
Noticed this output from QtCreator while debugging my test App, could it be relevant to my problem ?
/EGL_emulation: app_time_stats: avg=500.33ms min=498.20ms max=501.49ms count=3
W/qtMainLoopThrea: type=1400 audit(0.0:9194): avc: denied { read } for name="usb" dev="tmpfs" ino=713 scontext=u:r:untrusted_app:s0:c213,c256,c512,c768 tcontext=u:object_r:usb_device:s0 tclass=dir permissive=0 app=org.qtproject.example.QtTest4D
W/qtMainLoopThrea: type=1400 audit(0.0:9195): avc: denied { read } for name="/" dev="tmpfs" ino=1 scontext=u:r:untrusted_app:s0:c213,c256,c512,c768 tcontext=u:object_r:device:s0 tclass=dir permissive=0 app=org.qtproject.example.QtTest4D
W/qtMainLoopThrea: type=1400 audit(0.0:9196): avc: denied { read } for name="devices" dev="sysfs" ino=4521 scontext=u:r:untrusted_app:s0:c213,c256,c512,c768 tcontext=u:object_r:sysfs:s0 tclass=dir permissive=0 app=org.qtproject.example.QtTest4D
D/EGL_emulation: app_time_stats: avg=500.41ms min=499.71ms max=501.11ms count=2I expect the usb open I have in my code to fail in an Android context it is looking for a particular usb dongle in a Linux context. But this again seems to be a permissons issue at the lowest level???
-
Hi everyone. I'm new here out of curiosity.
I don't know if I can be of any help, but try asking Grok.Thanks, but Grok was unable to help.
-
Thanks, but Grok was unable to help.
Ok giving up on a programatic C++ solution and going down the AndroidManifest.xml route.
The setting of the screen in Landscape works <added: android:screenOrientation="landscape"> to the AndroidManifest.xml file.
From the Android devlopers site [https://developer.android.com/develop/background-work/background-tasks/awake/screen-on] they recommend adding:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:keepScreenOn="true"> </RelativeLayout>
I have tried this code in the AndroidManifest.xml file. However this results in a build error:
AAPT: error: unexpected element <RelativeLayout> found in <manifest>
Can anyone suggest the correct syntax and/or the correct file to include it in?
-
Ok giving up on a programatic C++ solution and going down the AndroidManifest.xml route.
The setting of the screen in Landscape works <added: android:screenOrientation="landscape"> to the AndroidManifest.xml file.
From the Android devlopers site [https://developer.android.com/develop/background-work/background-tasks/awake/screen-on] they recommend adding:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:keepScreenOn="true"> </RelativeLayout>
I have tried this code in the AndroidManifest.xml file. However this results in a build error:
AAPT: error: unexpected element <RelativeLayout> found in <manifest>
Can anyone suggest the correct syntax and/or the correct file to include it in?
Found this piece of java code which I have built in my project. How do I get it executed as part of an activity in my AndroidManifest.xml file.
import android.app.Activity; import android.os.Bundle; import android.view.WindowManager; public class KeepScreenOn extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Keep the screen on getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } }
-
Found this piece of java code which I have built in my project. How do I get it executed as part of an activity in my AndroidManifest.xml file.
import android.app.Activity; import android.os.Bundle; import android.view.WindowManager; public class KeepScreenOn extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Keep the screen on getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } }
-
Add :
<activity android:name="KeepScreenOn"> </activity>
To AndroidManifest.xml compiles but does not work!!?
Someone suggested adding
setContentView(R.layout.activity_main);
Above the getwindow() call in the java file.
but this errors on building with:
/work/Qt-Android/QtTest4/build/Android_Qt_6_9_1_qt_androidX86_Clang_x86_64-Debug/android-build/src/KeepScreenOn.java:9: error: package R does not exist
setContentView(R.layout.activity_main); -
Someone suggested adding
setContentView(R.layout.activity_main);
Above the getwindow() call in the java file.
but this errors on building with:
/work/Qt-Android/QtTest4/build/Android_Qt_6_9_1_qt_androidX86_Clang_x86_64-Debug/android-build/src/KeepScreenOn.java:9: error: package R does not exist
setContentView(R.layout.activity_main);Could not get anything to work apart from adding:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
To the QtActivity.java file onCreate method. Which does work. Not an elegant solution but it will do until I can find a better way.