一个人怎么可以检测屏幕手势之外的人自己的应用程序? [英] How can one detect screen gestures outside ones own app?

查看:153
本文介绍了一个人怎么可以检测屏幕手势之外的人自己的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有这么严重皱眉头的我怎么做的问题,但我看不出办法解决它这个时候。

我是一名经验丰富的专家和Android开发者,所以我觉得真的很愚蠢的问这个问题,但我刚刚安装的这个程序 而且它的东西,我认为是不可能的。

也就是说,监听屏手势(在这种情况下,刷卡从屏幕的边缘向内),无论您身在何处您的设备... ...的意思,它监听当你在启动程序主屏幕,当你在其他应用的重...不管你在做什么,它的听力和它检测到来自它可以让你带出一个隐藏设置抽屉,然后生活作为一个透明的(片段?对话框,屏幕边缘的刷卡时? )查看上任何其他应用程序,你在和解雇时(通过按BACK)的顶部离开你,无论你是在你的previous经验。

老实说,我不知道这是怎么可能的,更喜欢在一个正确的方向轻推。

解决方案

有两件事情你必须处理:

  1. 显示在顶部视图。对于这一点,你需要使用特殊权限<一href="http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#TYPE_SYSTEM_ALERT"相对=nofollow> TYPE_SYSTEM_ALERT 。这里有一个$ C $下显示在顶部视图:

     最后WindowManager.LayoutParams参数=新WindowManager.LayoutParams();
    param.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    最终的视图中查看= findViewById(R.id.view1);
    最后的ViewGroup家长=(ViewGroup中)view.getParent();
    如果(父!= NULL)
      parent.removeView(视图);
    param.format = PixelFormat.RGBA_8888;
    param.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    param.gravity = Gravity.TOP | Gravity.LEFT;
    param.width = view.getLayoutParams()宽。
    param.height = view.getLayoutParams()的高度。
    最后的窗口管理wmgr =(窗口管理器)getApplicationContext()getSystemService(Context.WINDOW_SERVICE)。
    wmgr.addView(查看,参数);
    // TODO处理重叠的标题栏和/或操作栏
    // TODO必须添加逻辑删除视图
    // TODO必须使用特别许可才能使用这种方法:android.permission.SYSTEM_ALERT_WINDOW
     

  2. 保持应用程序活着。对于这一点,你需要创建一个在前台运行,这意味着它使用通知服务。 这里有一个链接

有很多是有这个能力的应用程序。第一个我见过WAS AirCalc

I know that SO frowns heavily on "how do I do this" questions, but I don't see a way around it this time.

I'm a seasoned and expert Android developer so I feel really goofy asking this question, but I just installed this app and it does something that I thought was impossible.

Namely, it listens for screen gestures (in this case swipes from edges of the screen inward) REGARDLESS of where you are on your device... meaning, it listens when you're on the Launcher home screens, and when you're in OTHER apps... no matter what you're doing, it's listening and when it detects the swipe from the edge of the screen it lets you bring out a hidden settings drawer which then lives as a transparent (fragment? dialog?) View on top of whatever other app you're in and when dismissed (by hitting BACK) leaves you wherever you were in your previous experience.

I honestly have no clue how this is possible and would really love a nudge in the right direction. [EDIT]

解决方案

there are 2 things you have to handle:

  1. showing a view on top. for this, you need to use a special permission TYPE_SYSTEM_ALERT . here's a code for showing a view on top:

    final WindowManager.LayoutParams param=new WindowManager.LayoutParams();
    param.flags=WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    final View view=findViewById(R.id.view1);
    final ViewGroup parent=(ViewGroup)view.getParent();
    if(parent!=null)
      parent.removeView(view);
    param.format=PixelFormat.RGBA_8888;
    param.type=WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    param.gravity=Gravity.TOP|Gravity.LEFT;
    param.width=view.getLayoutParams().width;
    param.height=view.getLayoutParams().height;
    final WindowManager wmgr=(WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
    wmgr.addView(view,param);
    // TODO handle overlapping title bar and/or action bar
    // TODO you must add logic to remove the view
    // TODO you must use a special permission to use this method :android.permission.SYSTEM_ALERT_WINDOW
    

  2. keeping the app alive. for this, you need to create a service that runs in the foreground, which means it uses a notification. here's a link.

there are plenty of apps that have this ability. the first one i've seen was AirCalc.

这篇关于一个人怎么可以检测屏幕手势之外的人自己的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆