简体   繁体   English

在服务中获取前台活动的上下文

[英]Get context of foreground activity in Service

I have a service and I want to get context of topmost activity which is currently running on foreground. 我有一个服务,我想获取当前正在前台运行的最高活动的上下文。 The service is in my own app and topmost activity is from another app (the activity is not from my app). 该服务位于我自己的应用程序中,最重要的活动来自另一个应用程序(该活动不是来自我的应用程序)。 Is it possible ? 可能吗 ? If yes, how? 如果是,怎么办?

Edit : I need to get context because, I want to apply custom distortion to images rendered by Google VR service. 编辑:我需要获取上下文,因为我想对Google VR服务渲染的图像应用自定义失真。 How I plan to do is: 我打算怎么做:

  1. Get context of GvrActivity in my service. 在我的服务中获取GvrActivity的上下文。
  2. Get GvrView from the context 从上下文获取GvrView
  3. Access onDrawFrame() methods etc. from GvrView and apply custom distortion 从GvrView访问onDrawFrame()方法等并应用自定义变形

Service cannot get context of current active activity. 服务无法获取当前活动的上下文。 But you achieve your scenario other way. 但是您可以通过其他方式实现您的方案。

  1. Send the local broadcast when the job is finished on service, ( Services can access share preference , Database , broadcast reciever and etc..). 作业完成服务后发送本地广播( Services可以访问share preferenceDatabasebroadcast reciever等。)
  2. Listen the local broadcast from activity, onReceive() , on that function apply custom distortion to images rendered by google vr service. 监听来自活动onReceive()的本地广播,在该函数上将自定义失真应用于由Google VR服务渲染的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM