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

相关推荐
拭心11 小时前
Google 提供的 Android 端上大模型组件:MediaPipe LLM 介绍
android
带电的小王14 小时前
WhisperKit: Android 端测试 Whisper -- Android手机(Qualcomm GPU)部署音频大模型
android·智能手机·whisper·qualcomm
梦想平凡14 小时前
PHP 微信棋牌开发全解析:高级教程
android·数据库·oracle
元争栈道14 小时前
webview和H5来实现的android短视频(短剧)音视频播放依赖控件
android·音视频
阿甘知识库15 小时前
宝塔面板跨服务器数据同步教程:双机备份零停机
android·运维·服务器·备份·同步·宝塔面板·建站
元争栈道16 小时前
webview+H5来实现的android短视频(短剧)音视频播放依赖控件资源
android·音视频
MuYe16 小时前
Android Hook - 动态加载so库
android
居居飒17 小时前
Android学习(四)-Kotlin编程语言-for循环
android·学习·kotlin
Henry_He20 小时前
桌面列表小部件不能点击的问题分析
android
工程师老罗20 小时前
Android笔试面试题AI答之Android基础(1)
android