android - Flutter 应用程序 - 能够关闭设备
问题描述
有什么方法可以从 Android 上的 Flutter 应用程序关闭设备?我说的是当用户通过长按电源按钮关闭设备时发生的相同操作。
解决方案
您可以使用以下代码关闭您的 Android 设备:
Intent requestShutdownIntent = new Intent("com.android.internal.intent.action.REQUEST_SHUTDOWN");
requestShutdownIntent.putExtra("android.intent.extra.KEY_CONFIRM", false);
requestShutdownIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(requestShutdownIntent);
推荐阅读
- android - onResume 在视图模型中不起作用
- javascript - 如何使用 javascript 中的位置查找单词或子字符串?
- python - 具有固定数量的元素和固定间隔的 Python 范围
- android - Android ACTION_SEND (MULTIPLE) Intent 不会将文件发送到 Google Drive
- java - okHttp3 JVM 崩溃
- python - 在python中查找并检查行
- javascript - 无法在反应本机应用程序中清除 setInterval
- java - 错误:无法从静态上下文中引用非静态方法 LetConnect() Connection conn= LetConnect();
- reactjs - 如何在减速器中返回一个数组?
- java - 蓝牙服务器重启后 BLE 配对出现问题