Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Floating app on Android (Windowed app)

Does anyone know how I can create a floating window? (Image below shows what I mean) - source code

I've read on various websites that in order to do so an app must be running as a service which should in turn be running as an activity using 'TYPE_SYSTEM_ALERT'.

If the above is or isn't true ... I still don't know how to implement the code. Can someone write some code showing how a simple app (click button and do something) can be made into a floating window, Thank You :)

This may also help - facebook chatheads

Floating Window App

like image 817
daka Avatar asked Feb 13 '23 09:02

daka


2 Answers

The simplest way is to use the great open source Standout library: https://github.com/pingpongboss/StandOut

like image 75
FD_ Avatar answered Feb 24 '23 10:02

FD_


You can use WindowManager to inflate a view. Something like this:

LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);


overlay = (RelativeLayout) inflater.inflate(R.layout.overlay, null);

final LayoutParams params = new LayoutParams(
                        LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
                        LayoutParams.TYPE_SYSTEM_ALERT,
                        LayoutParams.FLAG_NOT_FOCUSABLE | LayoutParams.FLAG_NOT_TOUCH_MODAL,
                        PixelFormat.TRANSLUCENT);


WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
if (overlay.isShown()){
        wm.updateViewLayout(overlay, params);
}
else {

        // add overlay
        wm.addView(overlay, params);
}

Whit this you can inflate any view on any application.

Hope it helps you!!

like image 39
Alejandro Martínez Martínez Avatar answered Feb 24 '23 09:02

Alejandro Martínez Martínez