高通Android 12/Android 13截屏

正常截屏Power+音量-键 组合键同时长按,实现截屏逻辑。

PhoneWindowManager #init #interceptScreenshotChord

复制代码
init(Context context, IWindowManager windowManager,
            WindowManagerFuncs windowManagerFuncs)

2、在PhoneWindowManager中init方法中注册广播

frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java

复制代码
        // zm fix
		IntentFilter screenfilter = new IntentFilter();
        screenfilter.addAction("android.intent.action.SCREEN_SHOT");
		context.registerReceiver(mScreenshotReceiver, screenfilter);

3、广播实现代码如下图所示

复制代码
    private BroadcastReceiver mScreenshotReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        if ("android.intent.action.SCREEN_SHOT".equals(intent.getAction())) {
			Log.e("Receive Screen Shot Action","Screen Shot="+intent.getAction());
			String path = intent.getStringExtra("path");
            Log.e("onReceive", "Screenshot path: " + path);
            interceptScreenshotChord();
			copyLatestFile("/sdcard/Pictures/Screenshots",path);
			Log.e("onReceive", "Screenshot path completed: " + path);
			
        }
    }
};

4、自定义Service里面发送广播 代码如下所示

复制代码
 /**
     * 截屏
     *
     * @param path
     */
    public boolean capture(String path) {
		Log.e("capture","=========start capture=============");
		Intent intent = new Intent("android.intent.action.SCREEN_SHOT");
		intent.putExtra("path", path);
        mContext.sendBroadcast(intent);
	 
    }

5、PhoneWindowManager中调用 是发广播到 PhoneWindowManager interceptScreenshotChord中调用,具体源码细节,大家感兴趣去源码跟下哈,这里不再赘述哈。

复制代码
    private void interceptScreenshotChord() {
        mHandler.removeCallbacks(mScreenshotRunnable);
        mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
        mScreenshotRunnable.setScreenshotSource(SCREENSHOT_KEY_CHORD);
        mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
    }

6、最后截屏具体实现代码逻辑 如下所示

复制代码
private class ScreenshotRunnable implements Runnable {
        private int mScreenshotType = TAKE_SCREENSHOT_FULLSCREEN;
        private int mScreenshotSource = SCREENSHOT_KEY_OTHER;

        public void setScreenshotType(int screenshotType) {
            mScreenshotType = screenshotType;
        }

        public void setScreenshotSource(int screenshotSource) {
            mScreenshotSource = screenshotSource;
        }

        @Override
        public void run() {
            mDefaultDisplayPolicy.takeScreenshot(mScreenshotType, mScreenshotSource);
        }
    }

    private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable();

到这里基本结束,转载请注明出处,高通Android 12/Android 13截屏-CSDN博客谢谢!

相关推荐
笔夏10 分钟前
【安卓学习之myt】adb常用命令
android·学习·adb
lxysbly22 分钟前
安卓gba模拟器下载
android
bst@微胖子39 分钟前
CrewAI+FastAPI实现多Agent协作完成软件编码项目
android·fastapi
Android-Flutter41 分钟前
Compose - Scaffold使用
android·kotlin
2501_946244782 小时前
Flutter & OpenHarmony OA系统图片预览组件开发指南
android·javascript·flutter
极客小云2 小时前
【IEEE Transactions系列期刊全览:计算机领域核心期刊深度解析】
android·论文阅读·python
wanghowie2 小时前
02.01 Spring Boot|自动配置机制深度解析
android·spring boot·后端
一起搞IT吧2 小时前
三方相机问题分析十一:【手电筒回调异常】手电筒打开3档时,达到档位控制温度,手电筒二级界面中档位为0
android·图像处理·数码相机
2501_924064112 小时前
2025年移动应用渗透测试流程方案及iOS安卓测试方法对比
android·ios
千里马学框架2 小时前
安卓14-16车机手机仿小米su7三分屏实战项目专题
android·智能手机·framework·分屏·车载·小米汽车·三分屏