Android 7.1.1 系統截屏
阿新 • • 發佈:2017-09-19
return 應該 region imp pre back roi style 線程
frameworks/base/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java
TakeScreenshotService.java
package com.android.systemui.screenshot; import android.app.Service; import android.content.Intent; import android.os.Handler; import android.os.IBinder; import android.os.Message;import android.os.Messenger; import android.os.RemoteException; import android.os.UserManager; import android.util.Log; import android.view.WindowManager; public class TakeScreenshotService extends Service { private static final String TAG = "TakeScreenshotService"; private static GlobalScreenshot mScreenshot;private Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { final Messenger callback = msg.replyTo; Runnable finisher = new Runnable() { @Override public void run() { Message reply= Message.obtain(null, 1); try { callback.send(reply); } catch (RemoteException e) { } } }; // If the storage for this user is locked, we have no place to store // the screenshot, so skip taking it instead of showing a misleading // animation and error notification. if (!getSystemService(UserManager.class).isUserUnlocked()) { Log.w(TAG, "Skipping screenshot because storage is locked!"); post(finisher); return; } if (mScreenshot == null) { mScreenshot = new GlobalScreenshot(TakeScreenshotService.this); } switch (msg.what) { case WindowManager.TAKE_SCREENSHOT_FULLSCREEN: mScreenshot.takeScreenshot(finisher, msg.arg1 > 0, msg.arg2 > 0); break; case WindowManager.TAKE_SCREENSHOT_SELECTED_REGION: mScreenshot.takeScreenshotPartial(finisher, msg.arg1 > 0, msg.arg2 > 0); break; } } }; @Override public IBinder onBind(Intent intent) { return new Messenger(mHandler).getBinder(); } @Override public boolean onUnbind(Intent intent) { if (mScreenshot != null) mScreenshot.stopScreenshot(); return true; } }
主要是創建一個 GlobalScreenshot 對象,通過GlobalScreenshot對象實現截屏,之所以將該類宿主在service裏面是因為截屏可能產生耗時,這應該是設計時的理念。
當然完全可以由自己創建GlobalScreenshot對象,在線程裏面實現截屏.
Android 7.1.1 系統截屏