5

I want to write a service that sits in the background and when headset media button is pressed some specific ListView element from different app will be clicked.

Right now I'm only able to activate some specific Activity that has only ListView element. Is it possible to trigger such an click event (consider creating some kind of shortcuts or macros e.g. like AutoHotkey in windows)

I've only came across this blog post: http://mylifewithandroid.blogspot.com/2009/01/generating-keypresses-programmatically.html

I'm also aware of

View.performClick()

event. I can also mention that I can see the source code of the app I want to make shortcut to but I can't modify it and redistribute it. If it's not possible on a vanilla android than maybe rooted?

Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
pzo
  • 2,087
  • 3
  • 24
  • 42

1 Answers1

-2

Think about what you're doing, conceptually. Do you really want your program to understand external events as internal clicks?

Instead, point both events (the internal click, and the external event) at the same internal behavior.

externalEvent() -> performClick() // doesn't sound good.

externalEvent() -> doSomething();
onClick()       -> doSomething(); // looking better
salezica
  • 74,081
  • 25
  • 105
  • 166
  • He stated that he doesn't have the ability to alter the target application. This would be the right approach if both the service and the app were his, but not here. – Chris Cashwell Feb 23 '12 at 15:37
  • 1
    Oops. This is what happens when you get cocky and lecture without listening first. Downvote deserved. – salezica Mar 01 '12 at 21:44