Reputation: 33
I found this problem in the Android Developers Doc last month, but today I can't find it.
Have any idea can help me? Thanks!
Upvotes: 2
Views: 2877
Reputation: 1439
If we want to fire this action with intent, app should be a system app. This is from Android 11, not sure about other Android versions.
fun shutDownWithoutConfirmation(context: Context) {
try {
val intent = Intent("com.android.internal.intent.action.REQUEST_SHUTDOWN")
intent.putExtra("android.intent.extra.KEY_CONFIRM", false)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(intent)
}catch (e: Exception) {
e.printStackTrace()
}
}
fun shutDownWithConfirmation(context: Context) {
try {
val intent = Intent("com.android.internal.intent.action.REQUEST_SHUTDOWN")
intent.putExtra("android.intent.extra.KEY_CONFIRM", true)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(intent)
}catch (e: Exception) {
e.printStackTrace()
}
}
Upvotes: 0
Reputation: 1446
It might be removed from Docs because this is a hidden constant, at least on Android 9:
http://androidxref.com/9.0.0_r3/xref/frameworks/base/core/java/android/content/Intent.java#2638
/**
* Activity Action: Start this activity to request system shutdown.
* The optional boolean extra field {@link #EXTRA_KEY_CONFIRM} can be set to true
* to request confirmation from the user before shutting down. The optional boolean
* extra field {@link #EXTRA_USER_REQUESTED_SHUTDOWN} can be set to true to
* indicate that the shutdown is requested by the user.
*
* <p class="note">This is a protected intent that can only be sent
* by the system.
*
* {@hide}
*/
public static final String ACTION_REQUEST_SHUTDOWN
= "com.android.internal.intent.action.REQUEST_SHUTDOWN";
Upvotes: 4