wowamit
wowamit

Reputation: 3

Can one access Android API in a Java Application outside Android?

I want to access Android API classes outside an Android project. For example is it possible to get an object to the Context of the device connected to a machine or the running emulator?

This will allow access to a system services like PowerManager or ActivityManager outside an Android device. If not via Context object, is there any other way to access the system services for a device/avd outside Android?

Upvotes: 0

Views: 289

Answers (3)

Kristopher Micinski
Kristopher Micinski

Reputation: 7672

It sounds like what you're trying to do is not really access things on the device, as much as remotely control the device. In this case, there are some external tools that you should look into. The tools are mainly focused on testing, and are based on instrumentation for apps. You can look at robotium and monkeyrunner, to start with, as they provide a bit of functionality that might help you accomplish what you want. Other than that, you can also do what those tools do and write an app which listens for intents from adb, performs actions based on those intents, etc..., but you'll obviously be doing a lot of communication at a high level, so this might not be the most efficient (and I'm not sure how you'd transfer much data, which would be required for real RPC, which it sounds like you want to do).

Upvotes: 0

Konstantin Pribluda
Konstantin Pribluda

Reputation: 12367

No way. Distributed android API classes are merely stubs good enough to compile against them. Even most innocent stuff is stubbed out to throw RuntimeException on invocation. If you like to know status of the system, you will have to use SDK tools. Or write app exposing android objects via some remote access technology

Upvotes: 3

Ted Hopp
Ted Hopp

Reputation: 234807

I very much doubt that it is possible. The distributed SDK classes do not include many parts of the internal API. See, for example, this thread. Besides, what use would there be to have a system service object like PowerManager without a system (or an emulation of one) to back it up?

Upvotes: 0

Related Questions