How to record the Android Touch event?

Search This thread

maheng

New member
Apr 5, 2014
1
0
I have to record the touch event of any android (.apk) application. For that I have created the .jar(Library) file which is responsible to record touch event when user press any control. This .jar will be injected with any .apk file.

For achieve the above things I have follow the below step.

1)I have created application with only one button name App.apk.

2)Also Create the another library project called Test.jar

3)Give the dependency of Test.jar to App.apk.

Now I want send same event to test.jar. I have write below code in App.apk activity
@override
public void onResume()
{
super.onResume();
Test.Event.MyHook(this);
}

@override
public void onPause()
{
super.onPause();
Test.Event.MyUnHook(this);
}

@override
public boolean dispatchKeyEvent(android.view.KeyEvent event)
{
Test.Event.MyEvent(event);
return super.dispatchKeyEvent(event);
}
Can u suggest the way to get button click event from App.apk to Test.jar ?

Thanks
 

Androguide.fr

Account currently disabled
Jul 21, 2012
2,056
7,236
GB
meettomy.site
I have to record the touch event of any android (.apk) application. For that I have created the .jar(Library) file which is responsible to record touch event when user press any control. This .jar will be injected with any .apk file.

For achieve the above things I have follow the below step.

1)I have created application with only one button name App.apk.

2)Also Create the another library project called Test.jar

3)Give the dependency of Test.jar to App.apk.

Now I want send same event to test.jar. I have write below code in App.apk activity

@override
public void onResume()
{
super.onResume();
Test.Event.MyHook(this);
}

@override
public void onPause()
{
super.onPause();
Test.Event.MyUnHook(this);
}

@override
public boolean dispatchKeyEvent(android.view.KeyEvent event)
{
Test.Event.MyEvent(event);
return super.dispatchKeyEvent(event);
}
Can u suggest the way to get button click event from App.apk to Test.jar ?

Thanks
Seems rather fishy why you'd have to do that, but let's roll with it...^^

TLDR: in pure java, using standard APIs or even reflection or root, you can't.

You could use the android-event-injector project (which is a C++/JNI library) : https://code.google.com/p/android-event-injector/
It provides methods to listen to all input events, something like that (this will send all the results to logcat):
PHP:
public void StartEventMonitor() {
m_bMonitorOn = true;
Thread b = new Thread(new Runnable() {
  public void run() {
    while (m_bMonitorOn) {
      for (InputDevice idev:events.m_Devs) {
        // Open more devices to see their messages
        if (idev.getOpen() && (0 == idev.getPollingEvent())) {
          final String line = idev.getName()+
              ":" + idev.getSuccessfulPollingType()+
              " " + idev.getSuccessfulPollingCode() + 
              " " + idev.getSuccessfulPollingValue();
          Log.d(LT, "Event:"+line);
        }
      }
    }
  }
});
b.start();    
}

You can read more here: http://www.pocketmagic.net/2013/01/programmatically-injecting-events-on-android-part-2/


However, you might also be able to do that using the Xposed framework and finding a hook into the actual framework class for dispatchKeyEvent if it's the event you want to intercept.
I've never with Xposed so I can't really help you with the implementation, though, but it might be something to look into.
 
Last edited: