Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,768,001 Members 40,486 Now Online
XDA Developers Android and Mobile Development Forum

How to record the Android Touch event?

Tip us?
 
maheng
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 1
Join Date: Apr 2014
Unhappy How to record the Android Touch event?

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
Old
(Last edited by Androguide.fr; 7th April 2014 at 08:53 PM.)
#2  
Androguide.fr's Avatar
Recognized Contributor
Thanks Meter 6949
Posts: 2,053
Join Date: Jul 2012
Location: Lyon, France

 
DONATE TO ME
Quote:
Originally Posted by maheng View Post
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.

Quote:
My Contributions
(Apps, Librairies, Roms & Guides)
 

Pimp My Rom: Website / App / Thread

dSploit: Website / Github

Flash Gordon (Flash zips without a recovery): Thread

Universal init.d: App

PlayView/CardsUI Library: Portal / Github

HoloGraph Library: Portal / Github

Ubuntu Touch for i9300: Thread

Omni nightlies for Xperia Z1: Thread

Paranoid Android builds: Thread

Revive your bricked p68xx : Guide
Follow me on Github
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes