Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

How to record the Android Touch event?

OP maheng

5th April 2014, 09:43 AM   |  #1  
OP Junior Member
Thanks Meter: 0
 
1 posts
Join Date:Joined: Apr 2014
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
7th April 2014, 09:46 PM   |  #2  
Androguide.fr's Avatar
Recognized Contributor
Flag Lyon, France
Thanks Meter: 7,022
 
2,053 posts
Join Date:Joined: Jul 2012
Donate to Me
More
Quote:
Originally Posted by maheng

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 Code:
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() && (== 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/p...ndroid-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 by Androguide.fr; 7th April 2014 at 09:53 PM.
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes