How to programmatically disconnect an Android phone?

I want to make a lock screen application. When the phone is in lock mode, it will turn off the phone when USB is connected, so that other users cannot access the phone data. Does anyone know how to programmatically disable Android devices so that other people cannot access data while the device is in lock mode?

here is the code to lock the Home button in the activity of the lock screen:

@Override public void onAttachedToWindow() { this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); super.onAttachedToWindow(); } 
+6
source share
3 answers

This is not possible in the public Android SDK.

+5
source

Yes maybe

Using a system application (using firmware) does not load the application. You can get the code to turn off the Android device from AOSP.

+1
source

This is something that can give you an idea of ​​the OS you are working on, and not about developing an application that will work on any device, since you did not make an OS for them.

Just pull the android branch, configure it according to your desire and in mainfest remove the filters , permissions that do not allow you to do this , or add your own. Now you have to play with the battery if I'm talking about more depth.

But if you just want to trigger a click when you turn off the power, then its easier.

0
source

Source: https://habr.com/ru/post/898251/


All Articles