Android系统有自带的截屏方法,音量下键 + power键
但是有时候截屏并不是很方便,比如我们想获取是需要手指在屏幕上进行操作的画面,这样我们就不好去进行截屏操作
比如要获取下面的图,长按搜狗键盘上的T
当然,我们可以采用adb发送截屏命令进行截屏,但是如何采用更自然贴切的方法呢?
这个时候,延时截屏就有用了
音量下键 + power键的快捷截屏方式调用的是
frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
中的
private void interceptScreenshotChord() {
if (mScreenshotChordEnabled
&& mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
&& !mScreenshotChordVolumeUpKeyTriggered) {
final long now = SystemClock.uptimeMillis();
if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
&& now <= mScreenshotChordPowerKeyTime
+ SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
mScreenshotChordVolumeDownKeyConsumed = true;
cancelPendingPowerKeyAction();
Slog.d(TAG, "===== interceptScreenshotChord, mScreenshotRunnable");
mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
}
}
}
其中,
mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
调用系统截屏
如果要实现延时截屏,可以增加延时时间
mHandler.postDelayed(mScreenshotRunnable, 5*1000);//延时5s
另外,可以在PhoneWindowManager.java中注册广播接收来触发调用截屏操作
处理操作很简单清晰,关键的地方就是寻找到准确合适的操作位置