rovo89 / XposedInstaller

3.9k stars 1.51k forks source link

Communicating between Xposed and Classes like Activity or Service #245

Closed BenjaminFaal closed 10 years ago

BenjaminFaal commented 10 years ago

Hello,

Is there any function the call a method from an Activity or a Service.

Or at least a good way to share data between an Xposed module and other classes.

Kind regards,

Benjamin

theknut commented 10 years ago

You can install a broadcast receiver and send data via intents to your app. So every time you need to send data from your module to your app you can put all information in the intent and resolve it in your apps receiver.

You can also hook your own Activity and it's method(s). So in your Activity you call the method and with your xposed module you change the return value. But you won't be able to provide data you've collected with your module because you can't use your data across app hooks. This is only good for making your app know the module is up and running. In your app you create a method and return false. With your module you hook this method and return true. Am 29.11.2014 12:39 schrieb "BenjaminFaal" notifications@github.com:

Hello,

Is there any function the call a method from an Activity or a Service.

Or at least a good way to share data between an Xposed module and other classes.

Kind regards,

Benjamin

— Reply to this email directly or view it on GitHub https://github.com/rovo89/XposedInstaller/issues/245.

BenjaminFaal commented 10 years ago

Thanks for your quick response, my goal is calling a static method of an app.

Here is how i planned it, the Service i have will listen for any kind of button presses and then i want to call that method in the app.

Can you provide a sample, i already tried with a broadcast receiver but couldnt figure it out as im new to this subject.

theknut commented 10 years ago

I'm not on my PC right now but it's actually really simple once you know how to send intents and how to receive them. Just read up on intents and broadcast receivers. There are many samples already, it's not xposed specific. Just keep in mind that the receiver start is delayed on boot. So don't be confused when you don't see any results. Just wait until the boot is completed. Am 29.11.2014 13:07 schrieb "BenjaminFaal" notifications@github.com:

Thanks for your quick response, my goal is calling a static method of an app.

Here is how i planned it, the Service i have will listen for any kind of button presses and then i want to call that method in the app.

Can you provide a sample, i already tried with a broadcast receiver but couldnt figure it out as im new to this subject.

— Reply to this email directly or view it on GitHub https://github.com/rovo89/XposedInstaller/issues/245#issuecomment-64949755 .

BenjaminFaal commented 10 years ago

Ok nice, i will take a look, when i have any other questions i will ask here again. Thanks for your help so far!

theknut commented 10 years ago

Rather ask your questions in the appropriate XDA sub forum. Github is dedicated to the development. Am 29.11.2014 13:38 schrieb "BenjaminFaal" notifications@github.com:

Ok nice, i will take a look, when i have any other questions i will ask here again. Thanks for your help so far!

— Reply to this email directly or view it on GitHub https://github.com/rovo89/XposedInstaller/issues/245#issuecomment-64950488 .

simonbuehler commented 7 years ago

hi, sorry for jumping in on this so late, but this seems to be the only source where my exact problem is described:

i have a ButtonService which handles OnClickListeners and should be the single class where the data and logic to calculate the Location is kept,

ButtonService sends a broadcast to update the listeners, one of them is the module with the hooks.I use RemotePreferences in the module to read data altered in the ButtonService, so far so good and working.

Now there is also another hooked method that requests a new location which should be calculated in the ButtonService

so mostly the data flow is ButtonService -> broadcast --> xposed module (and others)

but whats best practice to implement

xposed beforehooked method -> call Buttonservice.calculateNewLoc() -> continue beforehooked Method?

simonbuehler commented 7 years ago

@theknut please give me some hints, much appreciated!!

theknut commented 7 years ago

I don't know man. I guess you can't do it that way because your code would have to wait until you get the new intent in order to continue. So your code won't run asynchronously and you might get performance issues or even freezes in cases of errors.

You might be able to call your calculateNewLoc method, exit the hooked method (set result null) and then call your calculateNewLoc method again after you received the new intent. You might have to send a few intents back and forth before actually be able to continue your hooked method.

Keine Ahnung was du machen willst, aber evtl. musst du einfach einen anderen Weg finden, um an deine Daten zu kommen. Drei, vier Intents hin und her zuschicken bevor die gehookte Methode ausgeführt werden kann klingt nicht gerade performant. Überleg mal, ob du das noch irgendwie anders regeln kannst. Viel Erfolg!

simonbuehler commented 7 years ago

thanks for the comment, at least i know now that i didn't miss something obvious here!