您的位置:首页 > 汽车 > 新车 > 高通Android 12/Android 13截屏

高通Android 12/Android 13截屏

2024/11/16 4:35:31 来源:https://blog.csdn.net/qq_15950325/article/details/139334457  浏览:    关键词:高通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 fixIntentFilter screenfilter = new IntentFilter();screenfilter.addAction("android.intent.action.SCREEN_SHOT");context.registerReceiver(mScreenshotReceiver, screenfilter);

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

    private BroadcastReceiver mScreenshotReceiver = new BroadcastReceiver() {@Overridepublic 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;}@Overridepublic void run() {mDefaultDisplayPolicy.takeScreenshot(mScreenshotType, mScreenshotSource);}}private final ScreenshotRunnable mScreenshotRunnable = new ScreenshotRunnable();

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com