0

I'm not sure if what I'm trying to achieve is possible.

I'm loading a class from another apk, like this:

final Class classToLoad = (Class<Object>) pathClassLoader.loadClass(classPath);

Which is all good, but I need to extend it, so I'm trying to create a Subclass which extends it:

class other extends classToLoad {...code to follow...}

But the compiler is moaning that it's expecting the class name instead of classToLoad

Is there any way around it?

Before I get shouted down, yes I'm trying to modify behaviour of another app, which I do not have the source code of, but I'm not trying to "hack" a paid app or similar, I'm only trying to start a service which isn't exported and the only way to start the service is to open the activity and tap on a menu item, and I'm trying to automate this, although I have a feeling I will be told this is not possible.

1 Answer 1

1

Is there any way around it?

Not that I am aware of, and it won't help.

although I have a feeling I will be told this is not possible.

It's not quite clear what loading a class from a foreign APK has to do with "open the activity and tap on a menu item". Regardless, there is nothing that you can do to start the service, except perhaps on rooted devices (where you might automate the actual UI of the other app, or modify its manifest to export the service, or something). Even if you somehow caused parts of the other app's UI to run in your process, that process is still your process, not the other app's process. Your process does not have any rights to start the non-exported service.

Sign up to request clarification or add additional context in comments.

4 Comments

Yes with rooted devices is easy. I was expecting a similar answer, well with a bit of reflection and creating a new instance of the Activity which has the menu buttons and then calling the onOptionsItemSelected might work, but I will need to somehow pass a context to the new instance, where to context is created from the other apk. But if I cannot extend the class there isn't anything I can do. Thanks for the answer.
@EmilBorconi: "creating a new instance of the Activity which has the menu buttons and then calling the onOptionsItemSelected might work" -- no, because it is still your process. Suppose that through the wave of a magic wand, a copy of that activity and all of its resources magically sprouted inside of your app. Why would that activity have any rights to start the service when an activity that you wrote by hand does not?
@EmilBorconi: Now, for testing purposes, you could write a test case using UiAutomator that automates the UI of the other app, and that would work, because it's the other app's process that is starting its own service. Similarly, there's probably a way with an AccessibilityService to accomplish your objective, by automating the other process' UI. The UiAutomator approach can't be shipped, and the AccessibilityService approach has lots of issues for public distribution, but for your own use, either could work.
I was trying not to use Accessibility, that requires user to allow access to it. Yes UiAutomator could be a solution I guess. I think I have missed how the "StartActivity" works actually. I was under the impression that if I create a new instance of the class it is the same as calling startactivity but not displaying anything, but reading more into it, startactivity actually creates the new instance in a separate thread... so no luck. Thanks for the time to answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.