高通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博客谢谢!

相关推荐
hnlgzb29 分钟前
请详细解释一下MVVM这个设计模型
android·kotlin·android jetpack·compose
❀͜͡傀儡师1 小时前
手机变AI助手:ApkClaw让闲置安卓机“再就业”
android·人工智能·智能手机
lxysbly1 小时前
鸿蒙FC红白机模拟器app下载
android·华为·harmonyos
陆业聪1 小时前
SystemUI 里做 Launcher App 列表:四种方案的 Framework 原理与工程取舍
android·framework·systemui·launcher
2501_915106322 小时前
iOS 多技术栈混淆实现,跨平台 App 混淆拆解与组合
android·ios·小程序·https·uni-app·iphone·webview
ii_best2 小时前
自动化开发软件[按键精灵] 安卓/iOS脚本,变量作用域细节介绍
android·运维·ios·自动化
00后程序员张3 小时前
有些卡顿不是 CPU 的问题,还要排查磁盘 I/O
android·ios·小程序·https·uni-app·iphone·webview
_李小白3 小时前
【OSG学习笔记】Day 24: Texture2D 与 Image
android·笔记·学习
FinTech老王3 小时前
告别“sql_mode“噩梦:MySQL 8.0 vs 5.7兼容性全对比与升级避坑指南
android·sql·mysql