WindowManager$BadTokenException: Unable to add window android.view.ViewRoot$W@4 5985ae0 — permission denied for this window type

巧了我就是萌 提交于 2019-12-12 05:59:57

问题


It's a long story, but I'm trying to call the ShutdownThread directory to restart the phone and for some reason it does not like my context, etc. as it gives me this error...any help would be appreciated....

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

回答1:


While calling your reboot() try giving getParent() for the context parameter and see.




回答2:


Try adding following permission in AndroidManifest. In case you don't have it.

android.permission.SYSTEM_ALERT_WINDOW



来源:https://stackoverflow.com/questions/6103401/windowmanagerbadtokenexception-unable-to-add-window-android-view-viewrootw4

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!