コード例 #1
0
ファイル: ScreenCapture.java プロジェクト: mirror/chromium
  @CalledByNative
  public void startCapture() {
    Log.d(TAG, "startCapture");
    synchronized (mCaptureStateLock) {
      if (mCaptureState != CaptureState.ALLOWED) {
        Log.e(TAG, "startCapture() invoked without user permission.");
        return;
      }
    }
    mMediaProjection = mMediaProjectionManager.getMediaProjection(mResultCode, mResultData);
    if (mMediaProjection == null) {
      Log.e(TAG, "mMediaProjection is null");
      return;
    }
    mMediaProjection.registerCallback(new MediaProjectionCallback(), null);

    mThread = new HandlerThread("ScreenCapture");
    mThread.start();
    mBackgroundHandler = new Handler(mThread.getLooper());

    // On Android M and above, YUV420 is prefered. Some Android L devices will silently
    // fail with YUV420, so keep with RGBA_8888 on L.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
      mFormat = PixelFormat.RGBA_8888;
    } else {
      mFormat = ImageFormat.YUV_420_888;
    }
    maybeDoRotation();
    createImageReaderWithFormat();
    createVirtualDisplay();

    changeCaptureStateAndNotify(CaptureState.STARTED);
  }
コード例 #2
0
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (requestCode != PERMISSION_CODE) {
     Log.e(TAG, "Unknown request code: " + requestCode);
     return;
   }
   if (resultCode != RESULT_OK) {
     Toast.makeText(this, "User denied screen sharing permission", Toast.LENGTH_SHORT).show();
     return;
   }
   mMediaProjection = mProjectionManager.getMediaProjection(resultCode, data);
   mMediaProjection.registerCallback(new MediaProjectionCallback(), null);
   mVirtualDisplay = createVirtualDisplay();
 }