如何在其他应用程序上绘制的应用程序上绘图?- 设置优先级?

3

感谢您的时间。

我正在开发一款应用程序,它可以在主屏幕和其他应用程序(如 fb messenger)上显示一个图标(见 img1),当您按下它时,该图标会显示具有选项的新活动(见 img3)。但是遇到了这个问题:

  • 图标显示在我的新覆盖活动后面(见 img3)
  • fb messager 总是出现在我的应用程序之上(见 img2)

所以我想也许存在一种方法来设置优先级来重叠屏幕?

  1. 如何在其他应用程序绘制在其他应用程序上时显示我的应用程序?

  2. 如何获得系统权限以出现在系统应用程序上方?

请帮忙。

Img1 - 我的应用程序

Img2 - 我的应用程序 vs Fb mssgr vs 系统应用程序

Img3 - 我创建了一个新的覆盖窗口,但我想要我的第一个图标出现

我的清单上的权限:

<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" />

图标服务:

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

    ....

    }

}

带有灰色叠加屏幕和底部白色图标的服务:

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

    ...
    }
}
2个回答

1
请查看Android文档
它说:
窗口类型:应用程序覆盖窗口显示在所有活动窗口(FIRST_APPLICATION_WINDOW和LAST_APPLICATION_WINDOW之间的类型)上方,但在状态栏或IME之类的关键系统窗口下方。
但紧接着它又说:
系统可能随时更改这些窗口的位置、大小或可见性,以减少对用户的视觉干扰并管理资源......系统将调整具有此窗口类型的进程的重要性,以减少低内存杀手杀死它们的机会。
结果是,你无法访问谁被放在前面或后面,系统为你确定,主要基于内存/CPU使用和屏幕空间。

0

我已经找到了一种方法来在其他应用程序上显示图标,那就是为每个应用程序添加不同的布局参数:

对于您想要置顶显示的屏幕:

LayoutParams.type = WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接