具有隐藏状态栏的Android浮动窗口辅助功能问题

时间:2014-05-12 12:01:20

标签: android accessibility android-4.4-kitkat android-fullscreen

我正在使用android 4.4.2构建一个带有由辅助功能服务创建的系统覆盖/浮动窗口的应用程序。

编辑:我希望能够隐藏状态栏GLOBALLY(在任何应用中)(通过下面的代码实现)但是当显示叠加时我停止从收听者接收acessibilityEvents软件/硬件后退按钮 当浮动视图注入windowmanager时:

  1. AccessibilityEvent侦听器未收到更新
  2. 软件/硬件返回键未注册(主页/近期确实)
  3. 为了隐藏状态栏 ' FLAG_FULLSCREEN |需要FLAG_NOT_TOUCH_MODAL' 才能触及屏幕的其余部分并且 ' View.SYSTEM_UI_FLAG_FULLSCREEN' 允许

    辅助功能服务(关于连接方法):

      @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);
    
            }
    

    辅助功能服务(关于连接方法):

    @Override
    public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
        Log.i("","Just log me some rubbish");
    
    }
    

    我的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"
        />
    

2 个答案:

答案 0 :(得分:1)

经过长时间和一周的研究后,我发现由于安全限制,无法做到这两点。我将在我的应用程序的根模式下实现这些功能。

我正在使用的解决方法是一个简单的按钮,用于恢复系统ui并删除阻止可访问性输入的视图

答案 1 :(得分:1)

嘿,我认为这会起作用!!!!

您只需要正确设置WindowManager.LayoutParams height width属性即可。 通过这种方式,您可以从侦听器和软件/硬件后退按钮接收acessibilityEvents。

试试这个

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;
}