'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:- 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 1:[1]
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
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Star4Droid |