从浮动窗口应用程序捕获整个屏幕的方法

时间:2019-04-27 12:32:19

标签: java android widget floating screen-capture

我正在尝试实现一个浮动的小部件按钮(例如Facebook Messenger),该按钮显示在另一个应用程序上。该按钮应该能够干扰其他应用程序的显示视图,并捕获下方的整个智能手机屏幕。

浮动按钮已经实现,可以在每个应用上正常使用。获取根视图并打印出此浮动视图的位图只会返回浮动按钮图像。我认为浮动窗口无法检测到下面应用程序的视图。

一个可能的解决方案是将另一个应用程序作为单独的活动启动并获取其视图,但是我不确定如何做到这一点。也许有一些更简单的方法可以实现这一目标?

//Creating the floating window and set its Layout parameters

mFloatViewLayoutParams = new WindowManager.LayoutParams();
mFloatViewLayoutParams.format = PixelFormat.TRANSLUCENT;
mFloatViewLayoutParams.flags = WindowManager.LayoutParams.FORMAT_CHANGED;

mFloatViewLayoutParams.type = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
                ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
                : WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
mFloatViewLayoutParams.gravity = Gravity.START;
mFloatViewLayoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
mFloatViewLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;

// adding the floatview to the WindowManager
LayoutInflater inflater = LayoutInflater.from(activity);
mFloatView = inflater.inflate(R.layout.float_view_layout, null);
mWindowManager.addView(mFloatView, mFloatViewLayoutParams);

...
// some clickListener to start the screenshot
ImageButton imageButton = mFloatView.findViewById(R.id.imageButton);
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                mActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        // here I want to get the view of the whole screen to 
                        screenshot it
                    }
                });
            }
        });

我不想要的内容:我不想对启动浮动按钮的主要活动的视图进行屏幕截图。

我真的不知道如何应对这一挑战。希望有人猜到了!

干杯!

0 个答案:

没有答案
相关问题