Angel
Angel

Reputation: 190

How to draw over apps that draw over other apps? - Setting Priorities?

thank you for your time.

I'm making this app that shows an icon over the home screen and other apps (like fb messenger) (see img1) and when you press it, the icon shows a new activity that has the options (see img3). But has this problem:

So I was thinking maybe there is a way to set the prioritys overlapping screens?

  1. How can I show my app over other apps that also draw over other apps?

  2. How can I get system permission to appear over the system app?

Please help.

Img1 - My app

Img2 - My app vs Fb mssgr vs System app

Img3 - I create a new overlay windows but I want my first icon appe

The permissions on my manifest:

<uses-permission android:name="android.permission.ACTION_MANAGE_OVERLAY_PERMISSION" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.CALL_PHONE" />

The Service of the Icon:

public class ServicioVentanaFlotanteIcono extends Service {


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


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

        // Indica que mostrará el Layout ventana_flotante
        final LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
        assert inflater != null;
        @SuppressLint("InflateParams") final View
                customView = inflater.inflate(R.layout.ventana_flotante_icono, null);

        // Inicializa el Windows Manager y muestra el Layout
        wm = (WindowManager) getSystemService(WINDOW_SERVICE);
        final WindowManager.LayoutParams parameters = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_PHONE,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);
        wm.addView(customView, parameters);

    ....

    }

}

The Service with the overlay gray screen and white icon on bottom:

public class ServicioVentanaFlotanteMensajes extends Service {

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

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

        // Indica que mostrará el Layout ventana_flotante_mensajes
        final LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
        customView = inflater.inflate(R.layout.ventana_flotante_mensajes, null);

        // Inicializa el Windows Manager y muestra el Layout
        wm = (WindowManager) getSystemService(WINDOW_SERVICE);
        final WindowManager.LayoutParams parameters = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.TYPE_PHONE,
                WindowManager.LayoutParams.FLAG_FULLSCREEN,
                PixelFormat.TRANSLUCENT);
        wm.addView(customView, parameters);

    ...
    }
}

Upvotes: 3

Views: 6161

Answers (2)

Angel
Angel

Reputation: 190

I have find a way to show the icon over the others apps, it was adding differents Layout params for each one:

To the screen you want shows on top:

LayoutParams.type = WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;

Upvotes: 0

Dylan
Dylan

Reputation: 1395

Take a look at the Android Documentation:

It states:

Window type: Application overlay windows are displayed above all activity windows (types between FIRST_APPLICATION_WINDOW and LAST_APPLICATION_WINDOW) but below critical system windows like the status bar or IME.

But then directly after it states this:

The system may change the position, size, or visibility of these windows at anytime to reduce visual clutter to the user and also manage resources.....

The system will adjust the importance of processes with this window type to reduce the chance of the low-memory-killer killing them.

The result is that you don't have access to who gets put in front or behind, the system determines it for you, and its primarily based on memory/cpu usage and screen space.

Upvotes: 1

Related Questions