0

I would like to write an application which can programatically generate touch events on the phone.

I have already tried this methods:

  • adb : adb swipe and so on... It requires USB cable and connect the phone to pc
  • adb ON TCPIP: same My problem with adb is to require so much presetting by user and I don't want to make the user to learn it. I have already made an application which use adb, but it's difficult for the user to set up properly :(

  • I have heard and I tried to sign my application with platform sign, but it's not good for me, because I would like to publish my app on android market and it is not a system application...

I would like to find a way to achieve this in a single application which can produce touch outside of the app (from background) and I would like to publish on market.

I have found this application: https://play.google.com/store/apps/details?id=com.teamviewer.quicksupport.samsung which can basically do this. Because when I click on my computer, it send a message to the phone and the phone make the touch on the screen. How and with what privileges can teamviewer do it?

Please give me some advice about it.

livemaker
  • 464
  • 1
  • 9
  • 19
László Leber
  • 281
  • 2
  • 5

2 Answers2

2

I would like to find a way to achieve this in a single application which can produce touch outside of the app (from background) and I would like to publish on market.

This is not possible, outside of what little input faking can be done by an accessibility service.

How and with what privileges can teamviewer do it?

If your read that Play Store listing, you will notice that it only works with Samsung devices. That is because the makers of TeamViewer struck a deal with Samsung to enable this sort of integration. Similarly, the TeamViewer team struck deals with a few other device manufacturers. However, they did not do so with all manufacturers, and so TeamViewer does not work on all devices.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I have seen that there is a Temviewer SDK as well, but I think it shares the screen only in app- – László Leber Jul 31 '17 at 11:45
  • As far as I know, they've not a deal with Samsung but using Knox SDK to do that, and asking the user for accepting this allowance. – forlayo Feb 22 '19 at 13:55
  • @forlayo: Nowadays, that may be true, but Teamviewer for Samsung predates KNOX, IIRC. – CommonsWare Feb 22 '19 at 14:12
  • @CommonsWare what about anydesk app it works on all devices? – Sahil Shokeen Apr 24 '20 at 05:44
  • @CommonsWare i decompiled AnyDesk apk and they are using INJECT_EVENTS permission to inject events on other apps using Instrumentation and InputManager classes, but when I tried to do the same on other apps, my app crashed with an error "Injecting events on other apps required INJECT_EVENTS permission" but I guess this is a system level permission, so can you please guide me regarding the same? – Sahil Shokeen Apr 24 '20 at 06:11
  • 1
    @SahilShokeen: `INJECT_EVENTS` is a `signature`-level permission. The only way your app can hold it is if it is signed by a platform signing key. AnyDesk has struck deals with a few device manufacturers to do this, apparently. – CommonsWare Apr 24 '20 at 11:05
  • @CommonsWare may I know how this thing works internally, how same app is signed with different signatures while installing that app? – Sahil Shokeen Apr 28 '20 at 16:43
  • @SahilShokeen: It is not "while installing that app". The developers of the app signed it before distributing it. For apps like TeamViewer, AFAIK the typical approach is that they send the unsigned APK to the manufacturer, who gives them the signed APK back (signed with the manufacturer's signing key). TeamViewer does this with each version of their app, for each manufacturer. – CommonsWare Apr 28 '20 at 16:53
  • @CommonsWare thanks a lot again for replying in your busy schedule. – Sahil Shokeen Apr 29 '20 at 03:49
0

Have a look here .This might be useful.

InputInjector Android library that eases the process of injecting InputEvents (MotionEvent, KeyEvent) to you Android app. The library uses internal API calls to inject events and depend on the accessability of these. This library will therefore not work on all devices but theoretically support Android 2.3 and forward (API level 9-18+).

Androd 2.3 (API level 9-15)

In older versions of Android we envoke the same system calls as used by the Instrumentation framework.

Permission No special permission needs to be set.

Androd 4.1.2 (API level 16 and forward)

As of API level 16 we have access to the InputManager class. We use this as the basis for the input injection.

Permission Using InputManager for injection requires setting permission android.permission.INJECT_EVENTS in your manifest.

Using this permission may require altering Lint Error Checking in order to be able to compile. In Eclipse this is done by going to Window->Preferences->Android->Lint Error Checking and then finding ProtectedPermissions and setting severity to something else than error.

NOTE: In order to inject events to other apps using InputManager, your apk must be signed with system level certificate.

https://github.com/arnebp/android-inputinjector

Community
  • 1
  • 1
NinjaStar
  • 1
  • 6
  • 1
    A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](//stackoverflow.com/help/deleted-answers) – Jonathan Mar 25 '19 at 13:47
  • @Jonathan is it ok? – NinjaStar Mar 25 '19 at 13:50