问题
I am working on android 4.4.2 building an application with a system overlay/floating window created by an accessibility service.
Edit:I want to be able to hide the status bar GLOBALLY (in any app) (made possible by the code below) however when the overlay is shown i stop receiving acessibilityEvents from the listener and the software/hardware back button When the floating view is injected into windowmanager:
- AccessibilityEvent listener does not receive updates
- Soft/hardware back key does not register (home/recents does)
in order to hide the status bar both 'FLAG_FULLSCREEN | FLAG_NOT_TOUCH_MODAL' are needed to allow touching the rest of the screen and 'View.SYSTEM_UI_FLAG_FULLSCREEN' allows
Accessibility Service (on connected method) :
@Override
public void onServiceConnected() {
serviceInstance = this;
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
FloatingView = new View(this);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
0, 0,
0, 0,
TYPE_PRIORITY_PHONE,
FLAG_FULLSCREEN | FLAG_NOT_TOUCH_MODAL, PixelFormat.OPAQUE);
params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
params.windowAnimations = android.R.style.Animation_Toast;
params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
windowManager.addView(FloatingView, params);
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
FloatingView.setSystemUiVisibility(uiOptions);
}
Accessibility Service (on connected method) :
@Override
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
Log.i("","Just log me some rubbish");
}
My AccessibilitySetup.xml:
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFeedbackType="feedbackAllMask"
android:notificationTimeout="0"
android:accessibilityFlags="flagDefault"
android:canRetrieveWindowContent="true"
android:description="@string/notification_description"
/>
回答1:
After long hours and a week of research i found theres is no way to do both of these due to security restrictions. i will implmenet these features in the root mode of my app.
the workaround i am using is a simple button that revives the system ui and removes the view that is blocking the accessibility input
回答2:
Hey i think this would work!!!!
You just need to set WindowManager.LayoutParams height width property correctly. By this you can able to receiving acessibilityEvents from the listener and the software/hardware back button.
Try this
WindowManager manager = ((WindowManager) context.getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE));
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
// this is to enable the notification to receive touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = retrieveStatusBarHeight(context);
localLayoutParams.format = PixelFormat.TRANSPARENT;
StatusBarOverlayView view = new StatusBarOverlayView(context);
manager.addView(view, localLayoutParams);
public static int retrieveStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
来源:https://stackoverflow.com/questions/23608475/android-floating-window-with-hidden-statusbar-accessibility-problems