2

I need to register a broadcast receiver that will tell me any kind of Drag events throughout the system. My app will run at background and perform any task if any kind of Drag event happens even any other app is running in the foreground. Is it possible? Any idea on how can I do it?

Updates: Do not think I'm going to make keylogger. My app will be visible but will run in background. And all I want is simply to detect Drag events (drag to left, drag to right, drag to up and drag to down). I'll accept any answer if you can tell me about how can I display 4 buttons those are permant, on top of any other apps because this can also serve me what I want.

zmarties
  • 4,809
  • 22
  • 39
A. K. M. Tariqul Islam
  • 2,824
  • 6
  • 31
  • 48
  • This better not be possible, for privacy and security reasons. Apps generally cannot spy on the UI events of other apps, except perhaps on rooted devices. – CommonsWare Sep 03 '14 at 11:56
  • Thank you CommonsWare. I tried to move a robot by watching it's cam. I planned to use Skype video call for the video streaming and drag on the screen for the movement command. Now, I need to use Android to Android video streaming, am I right? Can you please share any idea how can I shortly achieve this? My conference is very close :( – A. K. M. Tariqul Islam Sep 04 '14 at 06:02
  • 1
    CommonsWare... in older versions of android(I think gingerbread and lower) this is possible using overlays. The overlays were able to record presses on the screen regardless of where they were done. – Edward Jezisek Sep 12 '14 at 17:20
  • 2
    @EdwardJezisek that is still possible on newer versions. The difference is that the older APIs allowed you to pass the touches through to the underlying app, which caused the security hole. Newer APIs still allow you to receive the touches, but they cannot be passed through anymore. – Richard Le Mesurier Sep 16 '14 at 12:20

4 Answers4

1

Your app can run without a "normal" UI by running as a Service, as per your link, but I think the code you linked may be slightly out of date.

Remember that your service must run in the foreground - the code is supplied there in your link, but not explicitly called. Without running in the foreground, the system could well stop your app rather than running it in the background.


When I created a task switcher using such overlays, I found it was necessary to use a TYPE_SYSTEM_ALERT rather than TYPE_SYSTEM_OVERLAY.

I declare my window parameters without FLAG_WATCH_OUTSIDE_TOUCH.

WindowManager.LayoutParams params =
        new WindowManager.LayoutParams(width, height, x, y,
                WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                PixelFormat.TRANSLUCENT);

Your service should also be sure to properly unregister the overlay view from the WindowManager when it ends. Without this, you app will leak memory.

public void onDestroy()
{
    super.onDestroy();
    if (overlay != null)
    {
        ((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(overlay);
        overlay = null;
    }
}

I see that this is done in OverlayView.destory() (note the incorrect spelling of that method name - it would be a good idea to use the correct name for that method).

Community
  • 1
  • 1
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
0

So your real requirement is to be able to pass some input to your app whilst allowing the screen to be dedicated to outputting video.

Have you thought about the following:

  • detecting tilt or orientation of the device to control direction
  • having 4 nfc tags, and detecting which of those you are over to change direction (may not give you a quick enough response)

It is also possible to have actions that are selectable directly from notifications, so you could have one or more notification that offer actions to control the direction, and simply allow the notification API to handle the job of appearing in front of the video.

Of course there are apps that manage to overlay their UI in front of other apps. Such an example is Thrutu, though you seem to be pushed for time, and getting such a solution working is not straightforward - see How do I implement a slide-out drawer on the Android's call screen?

Community
  • 1
  • 1
zmarties
  • 4,809
  • 22
  • 39
0

I found my answer here. I need to start a service.

A. K. M. Tariqul Islam
  • 2,824
  • 6
  • 31
  • 48
0

The library standout allows you to create floating applications(applications that go over other applications). I used this for a couple android applications I put on the market a while back. It makes creating the floating windows pretty simple. Check it out at:
http://forum.xda-developers.com/showthread.php?t=1688531

Edward Jezisek
  • 522
  • 4
  • 11