简体   繁体   English

我可以制作一个Android应用程序,以便在用户超过一定期限后自动关闭我的手机吗?

[英]Can I make an android application that should turn my phone off automatically when the user has passed a certain deadline?

I am working on a project and still thinking if it can work to make an android application that should turn the phone completely off when the user has passed a certain deadline. 我正在研究一个项目,但仍在思考是否可以制作一个Android应用程序,该应用程序应在用户超过一定期限后完全关闭手机。 and even if the user reset his settings the application still working. 即使用户重置了自己的设置,该应用程序仍然可以正常运行。 is it possible to do something like this ? 有可能做这样的事情吗?

Thanks. 谢谢。

It will work ( if rooted )... 它将工作( 如果扎根 )...

call 呼叫

runRootCmd("reboot -p"); // "-p" will power off

method: 方法:

public static void runRootCmd(String cmd) {
        if (TextUtils.isEmpty(cmd)) {
            return;
        }
        Process process;
        try {
            process = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(
                    process.getOutputStream());
            os.writeBytes(cmd + " ;\n");
            os.flush();

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int read;
            InputStream errIs = process.getErrorStream();
            while ((read = errIs.read()) != -1) {
                baos.write(read);
            }
            baos.write('\n');

            InputStream inIs = process.getInputStream();
            while ((read = inIs.read()) != -1) {
                baos.write(read);
            }

            byte[] data = baos.toByteArray();
            String result = new String(data);

            Log.d(TAG, "runRootCmd result: " + result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Android 应用程序中关闭手机蓝牙时,我可以识别信标吗? - Can I recognize beacons when my phone Bluetooth is turned off in the Android application? android-当我转动手机,mediaPlayer和应用程序停止时,我改变了视角 - android - I change the perspective when I turn my phone, my mediaPlayer and application stoping 用户从我的应用程序注销时关闭平板电脑 - Turn off tablet when user log out from my application 我可以在Eclipse打开时自动关闭adb吗? - Can I turn off adb automatically starting when Eclipse is open? 当我的应用程序在Android中运行时,如何打开Wifi? - How can I turn Wifi on when my application runs in Android? 手机收到通知后如何在没有任何用户交互的情况下自动打开 Android 应用程序 - How I can Open Android Application Automatically Once The Phone Received notification Without any user interaction 当我的手机在 Android 中关闭时,如何找到谁打来的电话 - How can I find who called when my phone was off in Android 当我关闭手机的互联网时,Kotlin 的 URL.readText() 崩溃 - Kotlin's URL.readText() crashes when I turn my phone's internet off android canvas打开我的手机时崩溃 - android canvas when on turn my phone it crash 当用户打开某个应用程序时启动我的应用程序 - Android - Launch my application when a user opens a certain application - Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM