WindowManager $ BadTokenException:无法添加窗口android.view.ViewRoot$W@4 5985ae0-拒绝此窗口类型的权限

问题描述

|| 这是一个很长的故事,但是我试图调用ShutdownThread目录来重新启动手机,并且由于某种原因,它不喜欢我的上下文,等等,因为它给了我这个错误...任何帮助将不胜感激。 ...
.NativeStart.main(Native Method)
     [exec] 05-23 16:32:36.354  5573  5573 W System.err: Caused by: android.view
.WindowManager$BadTokenException: Unable to add window android.view.ViewRoot$W@4
5985ae0 -- permission denied for this window type
     [exec] 05-23 16:32:36.362  5573  5573 W System.err:        at android.view.


/**
 * Request a clean shutdown,waiting for subsystems to clean up their
 * state etc.  Must be called from a Looper thread in which its UI
 * is shown.
 *
 * @param context Context used to display the shutdown progress dialog.
 * @param reason code to pass to the kernel (e.g. \"recovery\"),or null.
 * @param confirm true if user confirmation is needed before shutting down.
 */
public static void reboot(final Context context,String reason,boolean confirm) {
    mReboot = true;
    mRebootReason = reason;
    shutdown(context,confirm);
}
    

解决方法

在调用您的
reboot()
时,请尝试为上下文参数指定
getParent()
并参见。     ,尝试在AndroidManifest中添加以下权限。万一你没有它。   android.permission.SYSTEM_ALERT_WINDOW