Java Code Examples for android.media.projection.MediaProjectionManager#createScreenCaptureIntent()

The following examples show how to use android.media.projection.MediaProjectionManager#createScreenCaptureIntent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QPMScreenRecorderManager.java    From QPM with Apache License 2.0 5 votes vote down vote up
public void startRecorder(Activity activity) {
    if (isStart || activity == null || activity.isFinishing()) {
        return;
    }
    isStart = true;
    mediaProjectionManager = (MediaProjectionManager) QPMManager.getInstance().getContext().getSystemService(Context.MEDIA_PROJECTION_SERVICE);
    Intent intent = mediaProjectionManager.createScreenCaptureIntent();
    PackageManager packageManager = activity.getPackageManager();
    if (packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
        //存在录屏授权的Activity
        activity.startActivityForResult(intent, REQUEST_CODE);
    } else {
        onRecorderFailed(activity);
    }
}
 
Example 2
Source File: ScreenshotActivity.java    From EZScreenshot with Apache License 2.0 5 votes vote down vote up
public void createScreenCaptureIntent() {
    LogUtil.LOGI("startActivityForResult");
    MediaProjectionManager projectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
    Intent intent = projectionManager.createScreenCaptureIntent();
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivityForResult(intent, PERMISSION_CODE_MEDIA_PROJECTION);


}
 
Example 3
Source File: CaptureHelper.java    From Telecine with Apache License 2.0 5 votes vote down vote up
static void fireScreenCaptureIntent(Activity activity, Analytics analytics) {
  MediaProjectionManager manager =
      (MediaProjectionManager) activity.getSystemService(MEDIA_PROJECTION_SERVICE);
  Intent intent = manager.createScreenCaptureIntent();
  activity.startActivityForResult(intent, CREATE_SCREEN_CAPTURE);

  analytics.send(new HitBuilders.EventBuilder() //
      .setCategory(Analytics.CATEGORY_SETTINGS)
      .setAction(Analytics.ACTION_CAPTURE_INTENT_LAUNCH)
      .build());
}
 
Example 4
Source File: RequestCaptureActivity.java    From telescope with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void requestCapture() {
  MediaProjectionManager projectionManager =
      (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
  Intent intent = projectionManager.createScreenCaptureIntent();

  requestStartTime = System.currentTimeMillis();
  startActivityForResult(intent, REQUEST_CODE);
}
 
Example 5
Source File: PermissionDialogActivity.java    From SoloPi with Apache License 2.0 4 votes vote down vote up
/**
 * 处理录屏权限
 * @return
 */
@SuppressWarnings("NewApi")
private boolean processRecordPermission() {
    // 如果包含忽略录屏,直接跳过
    if (SPService.getBoolean(PERMISSION_SKIP_RECORD, false)) {
        return true;
    }

    if (Build.VERSION.SDK_INT < 21) {
        showAction(StringUtil.getString(R.string.record_screen_android_version_error, Build.VERSION.SDK_INT), getString(R.string.constant__confirm), new Runnable() {
            @Override
            public void run() {
                SPService.putBoolean(PERMISSION_SKIP_RECORD, true);
                processedAction();
            }
        });
        return false;
    }


    if (injectorService.getMessage(Constant.EVENT_RECORD_SCREEN_CODE, Intent.class) == null) {
        MediaProjectionManager mMediaProjectionManager = (MediaProjectionManager) getApplicationContext().getSystemService(MEDIA_PROJECTION_SERVICE);
        final Intent intent = mMediaProjectionManager.createScreenCaptureIntent();

        // 之前申请过,直接申请
        if (SPService.getBoolean(PERMISSION_GRANT_RECORD, false)) {
            startActivityForResult(intent, MEDIA_PROJECTION_REQUEST);
        }

        showAction(StringUtil.getString(R.string.record_screen_permission), getString(R.string.permission__i_grant), new Runnable() {
            @Override
            public void run() {
                if (injectorService.getMessage(Constant.EVENT_RECORD_SCREEN_CODE, Intent.class) != null) {
                    processedAction();
                    SPService.putBoolean(PERMISSION_GRANT_RECORD, true);
                } else {
                    LauncherApplication.toast(R.string.permission__no_record_info);
                }
            }
        }, getString(R.string.constant__confirm), new Runnable() {
            @Override
            public void run() {
                startActivityForResult(intent, MEDIA_PROJECTION_REQUEST);
            }
        });
        return false;
    }

    return true;
}