Search code examples
javaandroidoverlayandroid-permissionsandroid-windowmanager

how to display floating window without permission?


i tried to display floating window in android 10 / Core M01 using WindowManger, but i am not able to get "Display over apps" permission:- enter image description here i tried to use "WindowManager.LayoutParams.TYPE_TOAST" and "WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY" and "WindowManager.LayoutParams.TYPE_PHONE", and nothing work for me. i get the error:"BadTokenException: Unable to add window -- token null is not valid; is your activity running?" when i use TYPE_TOAST and the error of the permission is the other types. this app works fine without getting the permission: Mouse Cursor Touchpad, and many apps like universal Copy, Mobizen..etc how to solve that?


Solution

  • i fix it using WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY in Accessibility Service

    public class MyService extends AccessibilityService {
    @Override
    protected void onServiceConnected() {
    Context ctx=(Context)this;
    WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    WindowManager.LayoutParams wLP = new WindowManager.LayoutParams();
    wLP.type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
    //....etc
    }
    }