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

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

问题描述



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





但是,我想要的应用程序将超出任何这样的应用程序:(在photoshop中制作):





我看到这个问题创建系统覆盖窗口(始终在顶部),但在ICS中没有功能的布局。
此外,我想从我的应用程序中给出一个对话框,而不会最小化其他应用程序...

解决方案

有很多应用程序可以显示浮动视图,如:airbrowser,LilyPad,Stick it,AirTerm,Smart Taskbar,aircalc ...



无论如何,按顺序要实现此功能,您必须拥有一个名为android.permission.SYSTEM_ALERT_WINDOW的特殊权限,并使用以下方式:

 最后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句柄重叠标题栏和/或动作栏
// TODO你必须添加逻辑来删除视图
// TODO你必须使用特殊的权限来使用这个方法:android .permission.SYSTEM_ALERT_WINDOW
//如果您希望在离开应用程序时留下视图,请确保您的前台服务正在运行。


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

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:

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

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...

解决方案

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

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天全站免登陆