使用广播接收器将视图添加到当前正在运行的顶级活动中?
我可以将视图添加到广播接收器中的顶部活动吗?
ActivityManager am = (ActivityManager) mContext
.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
componentInfo.getClassName() 返回正在运行的顶级活动的类名。我还可以获取包名称。我可以在当前的顶级活动中添加视图或一些动画吗?在大多数情况下,我需要布局名称来绑定它,但我无法弄清楚如何做到这一点。
Can i add a view to the top activity in broadcast receiver.
ActivityManager am = (ActivityManager) mContext
.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
componentInfo.getClassName() returns the class name of the top activity running. I can also get the package name. Can I add a view or some animation on current top activity. I need the layout name in most cases to bind to it but I am not able to figure out how to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能这样做,如果这样做的话,这将是一个很大的安全问题。但是,您也许可以在其之上启动一个新的活动,并且不会覆盖整个屏幕?你最终想要实现什么目标?
You can't do that, it would be quite a security concern if you do. However you may be able to start a new activity that's on top of it and doesn't cover the entire screen? What are you ultimately trying to accomplish?
好的 。我想通了。我在后台启动了一个服务,然后我获取了 WindowManager,然后膨胀了要添加的视图。然后我使用了 windowmanager.addView(inflatedView) 。
Ok . i figured out . I started a service in the background , and then i got hold of the WindowManager and then inflated the view to be added . Then i used windowmanager.addView(inflatedView) .