首页 > 解决方案 > Flutter 应用程序 - 能够关闭设备

问题描述

有什么方法可以从 Android 上的 Flutter 应用程序关闭设备?我说的是当用户通过长按电源按钮关闭设备时发生的相同操作。

标签: androidflutter

解决方案


您可以使用以下代码关闭您的 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);

推荐阅读