3

I am writing an app in C++ that in has to lock the device at a specific moment in time, like if the user had pressed the lock button.

I found some java procedures like DevicePolicyManager that do what I want but didn't find anything that I can use in my C++ program. Does anyone know how this functionality can be implemented in C++ (besides the DevicePolicyManager, if there is another way)?

Christophe
  • 68,716
  • 7
  • 72
  • 138
jaiprelv
  • 31
  • 5
  • I'm not an android expert by any means, but it seems the Java/Kotlin API includes a lot of high-level functionality that the NDK does not. I believe you can use JNI to call the Java API functions from your native C++ app. – Romen Jan 13 '20 at 16:42
  • C/C++ on Android is for specific use cases (performance, existing code base, speciality libraries). Anything related to Android Framework like DevicePolicyManager is accessed only at the Java/Kotlin layer. So you'll have to invoke via JNI. – Morrison Chang Jan 13 '20 at 16:42
  • I think my question is not correctly done, I am not willing to use the DevicePolicyManager, I saw that is possible to use it but there is another way to do it in C++ that doesn't include DevicePolicyManager? – jaiprelv Jan 13 '20 at 16:44
  • Not possible without Android Framework. Would still be in Java/Kotlin. See: [Detecting when screen is locked](https://stackoverflow.com/q/8317331/295004). Realize that Android has its [Activity Lifecycle](https://developer.android.com/guide/components/activities/activity-lifecycle) so all apps go through framework (including games). – Morrison Chang Jan 13 '20 at 17:00

0 Answers0