gpt4 book ai didi

java - 如何绘制覆盖其他应用程序的应用程序? - 设定优先次序?

转载 作者:太空狗 更新时间:2023-10-29 13:44:20 24 4
gpt4 key购买 nike

感谢您的宝贵时间。

我正在制作这个应用程序,它在主屏幕和其他应用程序(如 fb messenger)上显示一个图标(请参阅 img1),当您按下它时,该图标会显示一个具有选项的新 Activity (请参阅 img3)。但是有这个问题:

  • 图标显示在我的新叠加 Activity 后面(参见 img3)
  • fb messegner 总是出现在我的应用程序上(参见 img2)

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

  1. 如何将我的应用显示在其他应用之上,而这些应用也绘制在其他应用之上?

  2. 如何获得系统权限以显示在系统应用上?

请帮忙。

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

我的 list 上的权限:

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

...
}
}

最佳答案

看看 Android Documentation :

它指出:

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.

但是紧接着它说:

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.

结果是您无法访问谁被放在前面或后面,系统会为您确定,并且主要基于内存/CPU 使用率和屏幕空间。

关于java - 如何绘制覆盖其他应用程序的应用程序? - 设定优先次序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57223723/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com