0

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. How I plan to do is:

  1. Get context of GvrActivity in my service.
  2. Get GvrView from the context
  3. Access onDrawFrame() methods etc. from GvrView and apply custom distortion
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Harsh Mahajan
  • 21
  • 1
  • 7
  • https://stackoverflow.com/questions/28066231/how-to-gettopactivity-name-or-get-current-running-application-package-name-in-lo – Sarthak Gandhi Jun 25 '18 at 02:47
  • I want context and not just package names. – Harsh Mahajan Jun 25 '18 at 03:03
  • What do you need it for? You might get more answers if you ask a more specific question. Maybe you wouldn't need the context at all. – josephus Jun 25 '18 at 03:08
  • @josephus I have added the reason to get context – Harsh Mahajan Jun 25 '18 at 03:22
  • Understood. I'd imagine what you're trying to do is impossible short of having your own flavor of Android. Imagine the horror when apps have the ability to modify how other apps are drawn (theming is different of course). – josephus Jun 25 '18 at 07:00
  • This is not possible. The `Context` of another app is in another OS process. For security reasons your app cannot access memory inside another application's OS process. And thank the Godess for that! – David Wasser Jun 25 '18 at 16:59
  • @DavidWasser thank you! Can you think of any other approach to apply custom distortion? Like apply extra barrel distortion to whatever any VR app is rendering? – Harsh Mahajan Jun 26 '18 at 01:16
  • Is it possible to do if phone is rooted? – Harsh Mahajan Jun 26 '18 at 09:06

1 Answers1

0

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..).
  2. Listen the local broadcast from activity, onReceive(), on that function apply custom distortion to images rendered by google vr service.
amlwin
  • 4,059
  • 2
  • 15
  • 34