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

Angel :

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:

  • The icon is shown behind my new overlay activity (see img3)
  • fb messegner always appears over my app (see img2)

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);

    ...
    }
}
Angel :

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;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=126831&siteId=1