N
N
Ninazu2019-08-06 17:35:10
Android
Ninazu, 2019-08-06 17:35:10

How to draw a timer on top of other applications?

How to make a transparent application that will not respond to input events, but pass them to the application below it? Or should it be done through a service that will draw on top of other applications?
The task is to draw the timer in the foreground, on top of all other applications.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Nikolaev, 2019-08-07
@Ninazu

Here I love to dig towards the overlay.
Only your application will need an additional permission.)

public class OverlayService extends Service {

    @Override
    public void onCreate() {
        super.onCreate();

        WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

        View overlay = /*  Твоя вью сдесь*/;

        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
            PixelFormat.TRANSLUCENT);
        windowManager.addView(overlay , params);
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }   
}

Don't forget to add to your manifest
and start it
You can disable tachi through
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question