androidfluttershutdown

Shut down android device using Flutter application Programmatically


I am making a flutter application for Android TV ( x96 mini) and I need to shut down and turn on this android device from the same flutter application. How could I implement this

I have tried Platform MethodChannel but couldn't execute


Solution

  • I think Platform channel should work. Here is the code form this answer:

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