Android 检查是否使用windowmanager显示视图

Android 检查是否使用windowmanager显示视图,android,overlay,android-windowmanager,Android,Overlay,Android Windowmanager,在使用WindowManager添加之前,如何知道是否显示了视图? 我需要在本机拨号程序中添加一个覆盖,但有时本机拨号程序会将mi自定义视图放在上面,我通过使用WindowManager多次添加元素来解决这个问题,但有时视图会显示两次 谢谢 private void callStartIncomingCallScreen(Context context, String incomingNumber) { startIncomingCallScreen(context, incomingN

在使用WindowManager添加之前,如何知道是否显示了视图? 我需要在本机拨号程序中添加一个覆盖,但有时本机拨号程序会将mi自定义视图放在上面,我通过使用WindowManager多次添加元素来解决这个问题,但有时视图会显示两次

谢谢

private void callStartIncomingCallScreen(Context context, String incomingNumber) {
    startIncomingCallScreen(context, incomingNumber);

    Timer timer = new Timer();

    for (int i = 0; i < 2; i++) {
        timer.schedule(new StartIncomingCallScreenTimerTask(context, incomingNumber), 100 * i);
    }
}


class StartIncomingCallScreenTimerTask extends TimerTask {

    private Context context;
    private String incomingNumber;

    StartIncomingCallScreenTimerTask(Context context, String incomingNumber) {
        this.context = context;
        this.incomingNumber = incomingNumber;
    }

    public void run() {
        Intent intent = new Intent(context, IncomingCallGuiService.class);
        context.startService(intent);
    }
}

您可以查看您的充气情况。您可以使用view.isShown进行检查。使用windowManager.addViewyourView添加视图时,调用isShown时返回true


希望它能帮助您。

您可以查看您的充气情况。您可以使用view.isShown进行检查。使用windowManager.addViewyourView添加视图时,调用isShown时返回true


希望对您有所帮助。

我编辑了问题并添加了代码@AlexLockWood代码缩进/格式不正确。。。这很难阅读。我编辑了问题并添加了代码@AlexLockWood代码缩进/格式不正确。。。这很难读。我认为它是视图。至少对于最新的api我认为它是视图。至少对于最新的api
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);
// add the overlay
wm.addView(view, params);