简体   繁体   中英

How to disable system dialog window or pop ups in android?

I am finding out a way to switch off my tablet automatically.

Right now when we long press power button, I get a confirmation for shutdown (Cancel or Ok). Is there a way to programmatically switch off the device without confirmation ?

Is this possible?

否。有适当权限的电话/平板电脑通常可以访问su / reboot命令,但对于现成的商用设备而言,没有:无法通过编程方式将其关闭。

This is a dicey one! As an app, you cant do much, but there is one way you can try this. Get a phone which is rooted and grants your application SuperUser permissions. Then you could try to run this piece of code from your APK.

Process mProcess = null;
DataOutputStream osStream;

try {
        mProcess = Runtime.getRuntime().exec("su");
    } catch (IOException e) {
        Log.e("Error","Unable to get SU permissions, quitting");
    }
    osStream = new DataOutputStream(mProcess.getOutputStream());
try {
        osStream.writeBytes("reboot");
        Thread.sleep(1000);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

Not a tested piece of code, but hopefully should give you some idea!

Although you can't really invoke the shutdown programmatically in non-rooted device, there's a way how to disable the confirmation dialog that occurs when you long-press the power button. There's a secret code

*#*#7594#*#* or *#7594#

which changes the power button behaviour - enables direct power off once the code enabled. You need to choose this code via default dialpad. Works on most Android phones.

Here's the list of some other secret codes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM