【问题标题】:Can I make an android application that should turn my phone off automatically when the user has passed a certain deadline?我可以制作一个安卓应用程序,当用户超过一定期限时自动关闭我的手机吗?
【发布时间】:2016-02-16 14:45:09
【问题描述】:

我正在做一个项目,但我仍在考虑是否可以制作一个 Android 应用程序,该应用程序应该在用户超过某个截止日期时完全关闭手机。即使用户重置了他的设置,应用程序仍然可以工作。有可能做这样的事情吗?

谢谢。

【问题讨论】:

  • 不,你不能。看this answer的评论。如前所述,只有使用系统固件签名密钥签名的应用程序才能重新启动。
  • @Joseph82 您在“非 root”设备上的权利...我的 S6 将通过您可以在下面找到的代码关闭。
  • 当然,我说的是非root设备;)

标签: android kernel


【解决方案1】:

它会起作用(如果植根)...

打电话

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

方法:

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();
        }
    }

【讨论】:

  • 好吧,我是新手,但应用程序还应该阻止用户打开手机或使用激活密钥或其他东西打开手机!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-02
  • 2019-11-13
  • 1970-01-01
相关资源
最近更新 更多