Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied for this type of window at android 6. #37

Closed
ch-muhammad-adil opened this issue Jul 13, 2016 · 1 comment
Closed

Permission denied for this type of window at android 6. #37

ch-muhammad-adil opened this issue Jul 13, 2016 · 1 comment

Comments

@ch-muhammad-adil
Copy link

ch-muhammad-adil commented Jul 13, 2016

Hey thank you for this library..

I am facing this issue at Android 6.

android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@480c247 -- permission denied for this window type
07-13 19:09:23.481 15732-15732/com.spoofer W/System.err:     at android.view.ViewRootImpl.setView(ViewRootImpl.java:599)
07-13 19:09:23.481 15732-15732/com.spoofer W/System.err:     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:310)
07-13 19:09:23.481 15732-15732/com.spoofer W/System.err:     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
07-13 19:09:23.481 15732-15732/com.spoofer W/System.err:     at com.spoofer.dp_widget.lib.StandOutWindow.show(StandOutWindow.java:1113)
07-13 19:09:23.481 15732-15732/com.spoofer W/System.err:     at com.spoofer.dp_widget.lib.StandOutWindow.onStartCommand(StandOutWindow.java:386)
07-13 19:09:23.481 15732-15732/com.spoofer W/System.err:     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3028)
07-13 19:09:23.481 15732-15732/com.spoofer W/System.err:     at android.app.ActivityThread.access$2200(ActivityThread.java:157)
@ch-muhammad-adil
Copy link
Author

ch-muhammad-adil commented Jul 13, 2016

So I have managed to solve this issue. here is my solution ...

We need to get permissions for this app to draw on system window so here I used this code

if (Build.VERSION.SDK_INT >= 23) {
            checkDrawOverlayPermission();
        }else{
            StandOutWindow.closeAll(this, Dpad.class);
            StandOutWindow.show(this, Dpad.class, StandOutWindow.DEFAULT_ID);
            finish();
        }

here is the rest work I have done.

get the permissions from the user

`/**
     * code to post/handler request for permission
     */
    public final static int REQUEST_CODE = 5463&0xffffff00;

    public void checkDrawOverlayPermission() {
        /** check if we already  have permission to draw over other apps */
        if (!Settings.canDrawOverlays(getApplicationContext())) {
            /** if not construct intent to request permission */
            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + getPackageName()));
            /** request permission via start activity for result */
            startActivityForResult(intent, REQUEST_CODE);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        /** check if received result code
         is equal our requested code for draw permission  */
        if (requestCode == REQUEST_CODE) {
//            / ** if so check once again if we have permission */
            if (Settings.canDrawOverlays(this)) {
                StandOutWindow.closeAll(this, Dpad.class);
                StandOutWindow.show(this, Dpad.class, StandOutWindow.DEFAULT_ID);
                finish();
            }
        }
    }`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant