Android studio:unable to add window android.view.viewrootimpl$w@5e2d85a--Permission denied for this window first line of code

Source: Internet
Author: User

The error that occurred while learning the first line of code.

Java.lang.RuntimeException:Unable to start receiver Com.example.sevenun.littledemo.receiver.ForceOfflineReceiver: android.view.windowmanager$badtokenexception:unable to add window [e-mail protected]--Permission denied for this window Type
At Android.app.ActivityThread.handleReceiver (activitythread.java:2732)
At ANDROID.APP.ACTIVITYTHREAD.-WRAP14 (Activitythread.java)
At Android.app.activitythread$h.handlemessage (activitythread.java:1421)
At Android.os.Handler.dispatchMessage (handler.java:102)
At Android.os.Looper.loop (looper.java:148)
At Android.app.ActivityThread.main (activitythread.java:5417)
At Java.lang.reflect.Method.invoke (Native Method)
At Com.android.internal.os.zygoteinit$methodandargscaller.run (zygoteinit.java:726)
At Com.android.internal.os.ZygoteInit.main (zygoteinit.java:616)
caused By:android.view.windowmanager$badtokenexception:unable to add window [e-mail protected]--permission denied for T His window type
At Android.view.ViewRootImpl.setView (viewrootimpl.java:591)
At Android.view.WindowManagerGlobal.addView (windowmanagerglobal.java:310)
At Android.view.WindowManagerImpl.addView (windowmanagerimpl.java:85)
At Android.app.Dialog.show (dialog.java:319)
At Com.example.sevenun.littledemo.receiver.ForceOfflineReceiver.onReceive (forceofflinereceiver.java:38)
At Android.app.ActivityThread.handleReceiver (activitythread.java:2725)
At ANDROID.APP.ACTIVITYTHREAD.-WRAP14 (Activitythread.java)
At Android.app.activitythread$h.handlemessage (activitythread.java:1421)
At Android.os.Handler.dispatchMessage (handler.java:102)
At Android.os.Looper.loop (looper.java:148)
At Android.app.ActivityThread.main (activitythread.java:5417)
At Java.lang.reflect.Method.invoke (Native Method)
At Com.android.internal.os.zygoteinit$methodandargscaller.run (zygoteinit.java:726)
At Com.android.internal.os.ZygoteInit.main (zygoteinit.java:616)

Because the program in the first line of code is mostly run in android4.x, the latest Android 6 has new requirements for the program's permissions.

So, we're going to start with the type WindowManager.LayoutParams.TYPE_SYSTEM_ALERT alertdialog:

If it is in the case of android4.x, use only androidmanifest.xml inside the declaration <uses-permission android:name= "Android.permission.SYSTEM_ALERT_ Window "/>.

If you are in Android 6 (API 23), you can add the following code to request permission, let the user agree before you can eject Alertdialog.

   

 @Override protected void OnCreate (Bundle savedinstancestate) {Super.on        Create (savedinstancestate);        Setcontentview (R.layout.activity_login); if (Build.VERSION.SDK_INT >=) {if (! Settings.candrawoverlays (Loginactivity.this)) {Intent Intent = new Intent (settings.action_manage_overlay_p                Ermission, Uri.parse ("package:" + getpackagename ()));            Startactivityforresult (intent,10); }}} @Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {if (Requestcode = = 10) {if (Build.VERSION.SDK_INT >=) {if (! Settings.candrawoverlays (This)} {//System_alert_window permission not granted ... T                Oast.maketext (Loginactivity.this, "not granted", toast.length_short); }            }        }    }

Reference: http://blog.csdn.net/chenlove1/article/details/52047105

Android studio:unable to add window [e-mail protected] --Permission denied for this window first line of code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.