让应用程序在其他应用程序之上运行 [英] Having application running above other app

查看:36
本文介绍了让应用程序在其他应用程序之上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个可以在任何应用程序上方打开的活动.

I want to make an activity that can be opened above ANY app.

通常情况下,即使将 Activity 设置为对话框,当您切换到我的应用程序时,您会看到我的应用程序,并在后台看到启动器:

Normally, even when the activity is set as dialog, when you switch to my app, you see my app, and in the background you see the launcher:

但是,我希望该应用程序能够超越任何这样的应用程序:(在 photoshop 中制作):

BUT, I want the app will go above any app like this: (made in photoshop):

我确实看到了这个问题 创建系统覆盖窗口(总是在顶部),但在 ICS 中没有布局功能.此外,我想在不最小化其他应用程序的情况下从我的应用程序中提供一个对话框...

I did see this question Creating a system overlay window (always on top), but in ICS there is no functionallity to the layout. Furthermore, I want to give a dialog box from my app without minimizing the other app...

推荐答案

有很多应用程序可以在所有内容的顶部显示浮动视图,例如:airbrowser、LilyPad、Stick it、AirTerm、Smart Taskbar、aircalc ...

there are plenty of apps that show a floating view on top of everything like : airbrowser , LilyPad , Stick it , AirTerm , Smart Taskbar , aircalc ...

无论如何,为了实现这个功能,你必须有一个叫做android.permission.SYSTEM_ALERT_WINDOW"的特殊权限,并使用类似的东西:

anyway , in order to achieve this feature , you must have a special permission called "android.permission.SYSTEM_ALERT_WINDOW" , and use something like that:

final WindowManager.LayoutParams param=new WindowManager.LayoutParams();
param.flags=WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
final View view=findViewById(R.id.my_floating_view);
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=parent!=null?LayoutParams.WRAP_CONTENT:view.getLayoutParams().width;
param.height=parent!=null?LayoutParams.WRAP_CONTENT: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
// TODO if you wish to let the view stay when leaving the app, make sure you have a foreground service running.

这篇关于让应用程序在其他应用程序之上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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