3

Dear all android Expert,

Currently, I grab an open source Android project (wso2 agent) that need to use the API startServiceAsUser() in Context class. However, android studio cannot recognize this API. How can I resolve this error?

sing lam
  • 131
  • 1
  • 10

1 Answers1

5

You cannot call that API because its not a public API from the perspective of the android SDK. This is a part of the framework internal APIs. Generally apps should NOT use these APIs, that is why they are hidden.

If you are trying to call it, you need to use reflection. But before you do, really evaluate if you absolutely have to use startServiceAsUser() as most apps are user centric and not singular, which is what this is needed for.

JoxTraex
  • 13,423
  • 6
  • 32
  • 45
  • Just to note that not only Reflection API can be used - you can replace in your Android SDK android.jar with one including those hidden API. WSO2 maintainers decided to use that approach, see my reply here: http://stackoverflow.com/a/41004248/1028256 – Mixaz Dec 06 '16 at 20:43