android.media.projection.MediaProjectionManager Java Examples

The following examples show how to use android.media.projection.MediaProjectionManager. 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: ScreenCapture.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@CalledByNative
public boolean allocate(int width, int height) {
    mWidth = width;
    mHeight = height;

    mMediaProjectionManager =
            (MediaProjectionManager) ContextUtils.getApplicationContext().getSystemService(
                    Context.MEDIA_PROJECTION_SERVICE);
    if (mMediaProjectionManager == null) {
        Log.e(TAG, "mMediaProjectionManager is null");
        return false;
    }

    WindowManager windowManager =
            (WindowManager) ContextUtils.getApplicationContext().getSystemService(
                    Context.WINDOW_SERVICE);
    mDisplay = windowManager.getDefaultDisplay();

    DisplayMetrics metrics = new DisplayMetrics();
    mDisplay.getMetrics(metrics);
    mScreenDensity = metrics.densityDpi;

    return true;
}
 
Example #2
Source File: ScreenRecorderService.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    try {
        createNotificationChannel();
        //Android Q 存在兼容性问题
        MediaProjectionManager mMediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
        MediaProjection mediaProjection = mMediaProjectionManager.getMediaProjection(Activity.RESULT_OK, (Intent) intent.getParcelableExtra("data"));
        ColorPickManager.getInstance().setMediaProjection(mediaProjection);
        if (ColorPickManager.getInstance().getColorPickerDokitView() != null) {
            ColorPickManager.getInstance().getColorPickerDokitView().onScreenServiceReady();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return super.onStartCommand(intent, flags, startId);
}
 
Example #3
Source File: ScreenCapture.java    From timecat with Apache License 2.0 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void createVirtualEnvironment() {
    dateFormat = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");
    strDate = dateFormat.format(new java.util.Date());
    pathImage = Environment.getExternalStorageDirectory().getPath() + "/Pictures/";
    nameImage = pathImage + strDate + ".png";
    mMediaProjectionManager1 = (MediaProjectionManager) activity.getApplication().getSystemService(Context.MEDIA_PROJECTION_SERVICE);
    mWindowManager1 = (WindowManager) activity.getApplication().getSystemService(Context.WINDOW_SERVICE);
    windowWidth = ViewUtil.getScreenWidth(activity);
    windowHeight = ViewUtil.getSceenHeight(activity);
    metrics = new DisplayMetrics();
    mWindowManager1.getDefaultDisplay().getMetrics(metrics);
    mScreenDensity = metrics.densityDpi;
    mImageReader = ImageReader.newInstance(windowWidth, windowHeight, 0x1, 2); //ImageFormat.RGB_565

    LogUtil.d(TAG, "prepared the virtual environment");
}
 
Example #4
Source File: MainActivity.java    From ScreenCapture with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);

    mBtnCapture.setOnClickListener(this);
    mBtnRecordScreen.setOnClickListener(this);
    mBtnRecordByCodec.setOnClickListener(this);
    mBtnRecordCamera.setOnClickListener(this);
    mBtnScanQR.setOnClickListener(this);
    mBtnRtsp.setOnClickListener(this);
    mBtnSocket.setOnClickListener(this);

    mProjectionManager = (MediaProjectionManager) getSystemService(
            Context.MEDIA_PROJECTION_SERVICE);

}
 
Example #5
Source File: MediaProjectionManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override // Binder call
public int applyVirtualDisplayFlags(int flags) {
    if (mType == MediaProjectionManager.TYPE_SCREEN_CAPTURE) {
        flags &= ~DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY;
        flags |= DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
                | DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION;
        return flags;
    } else if (mType == MediaProjectionManager.TYPE_MIRRORING) {
        flags &= ~(DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC |
                DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR);
        flags |= DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY |
                DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION;
        return flags;
    } else if (mType == MediaProjectionManager.TYPE_PRESENTATION) {
        flags &= ~DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY;
        flags |= DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC |
                DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION |
                DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
        return flags;
    } else  {
        throw new RuntimeException("Unknown MediaProjection type");
    }
}
 
Example #6
Source File: ScreenShotActivity.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public void requestScreenShot() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mMediaProjectionManager = (MediaProjectionManager) this.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
        try {
            startActivityForResult(mMediaProjectionManager.createScreenCaptureIntent(), REQUEST_MEDIA_PROJECTION);
        }catch (Exception ex){
            if (onSavedListener != null) {
                onSavedListener.onFinish(false);
            }
        }
    }
    else
    {
        Environment.toast(this, "系统版本过低,无法使用截屏功能。");
        if (onSavedListener != null) {
            onSavedListener.onFinish(false);
        }
    }
}
 
Example #7
Source File: ScreenCapturerAndroid.java    From VideoCRE with MIT License 6 votes vote down vote up
@Override
public synchronized void initialize(final SurfaceTextureHelper surfaceTextureHelper,
    final Context applicationContext, final VideoCapturer.CapturerObserver capturerObserver) {
  checkNotDisposed();

  if (capturerObserver == null) {
    throw new RuntimeException("capturerObserver not set.");
  }
  this.capturerObserver = capturerObserver;

  if (surfaceTextureHelper == null) {
    throw new RuntimeException("surfaceTextureHelper not set.");
  }
  this.surfaceTextureHelper = surfaceTextureHelper;

  mediaProjectionManager = (MediaProjectionManager) applicationContext.getSystemService(
      Context.MEDIA_PROJECTION_SERVICE);
}
 
Example #8
Source File: RecordingSession.java    From Telecine with Apache License 2.0 6 votes vote down vote up
RecordingSession(Context context, Listener listener, int resultCode, Intent data,
    Analytics analytics, Provider<Boolean> showCountDown, Provider<Integer> videoSizePercentage) {
  this.context = context;
  this.listener = listener;
  this.resultCode = resultCode;
  this.data = data;
  this.analytics = analytics;

  this.showCountDown = showCountDown;
  this.videoSizePercentage = videoSizePercentage;

  File picturesDir = Environment.getExternalStoragePublicDirectory(DIRECTORY_MOVIES);
  outputRoot = new File(picturesDir, "Telecine");

  notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
  windowManager = (WindowManager) context.getSystemService(WINDOW_SERVICE);
  projectionManager = (MediaProjectionManager) context.getSystemService(MEDIA_PROJECTION_SERVICE);
}
 
Example #9
Source File: ScreenCapturerAndroid.java    From webrtc_android with MIT License 6 votes vote down vote up
@Override
// TODO(bugs.webrtc.org/8491): Remove NoSynchronizedMethodCheck suppression.
@SuppressWarnings("NoSynchronizedMethodCheck")
public synchronized void initialize(final SurfaceTextureHelper surfaceTextureHelper,
    final Context applicationContext, final CapturerObserver capturerObserver) {
  checkNotDisposed();

  if (capturerObserver == null) {
    throw new RuntimeException("capturerObserver not set.");
  }
  this.capturerObserver = capturerObserver;

  if (surfaceTextureHelper == null) {
    throw new RuntimeException("surfaceTextureHelper not set.");
  }
  this.surfaceTextureHelper = surfaceTextureHelper;

  mediaProjectionManager = (MediaProjectionManager) applicationContext.getSystemService(
      Context.MEDIA_PROJECTION_SERVICE);
}
 
Example #10
Source File: MainActivity.java    From hyperion-android-grabber with MIT License 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mMediaProjectionManager = (MediaProjectionManager)
                                    getSystemService(Context.MEDIA_PROJECTION_SERVICE);

    ImageView iv = findViewById(R.id.power_toggle);
    iv.setOnClickListener(this);
    iv.setOnFocusChangeListener(this);
    iv.setFocusable(true);
    iv.requestFocus();

    setImageViews(mRecorderRunning, false);

    LocalBroadcastManager.getInstance(this).registerReceiver(
            mMessageReceiver, new IntentFilter(HyperionScreenService.BROADCAST_FILTER));
    checkForInstance();
}
 
Example #11
Source File: RecorderConfigActivity.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_record_config);

    initViews();

    mMediaProjectionManager = (MediaProjectionManager) getApplicationContext().getSystemService(MEDIA_PROJECTION_SERVICE);

    VideoUtils.findEncodersByTypeAsync(ScreenRecorder.VIDEO_AVC, new VideoUtils.Callback() {
        @Override
        public void onResult(MediaCodecInfo[] infos) {
            logCodecInfos(infos, ScreenRecorder.VIDEO_AVC);
            mAvcCodecInfo = infos;
            SpinnerAdapter codecsAdapter = createCodecsAdapter(mAvcCodecInfo);
            mVideoCodec.setAdapter(codecsAdapter);
            restoreSelections(mVideoCodec, mVideoResolution, mVideoFrameRate, mVideoBitrate);
        }
    });
}
 
Example #12
Source File: RecordService.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    LogUtil.d(TAG, "onCreate");
    results = new ArrayList<>();
    createView();

    mMediaProjectionManager = (MediaProjectionManager)getSystemService(Context.MEDIA_PROJECTION_SERVICE);
    mNotifications = new Notifications(getApplicationContext());
    mHandler = new Handler();
    injectorService = LauncherApplication.getInstance().findServiceByName(InjectorService.class.getName());
    injectorService.register(this);

    eventService = LauncherApplication.getInstance().findServiceByName(EventService.class.getName());
    eventService.startTrackTouch();
}
 
Example #13
Source File: MainActivity.java    From owt-client-android with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onClick(View v) {
    middleBtn.setEnabled(false);
    middleBtn.setTextColor(Color.DKGRAY);
    if (middleBtn.getText().equals("ShareScreen")) {
        MediaProjectionManager manager =
                (MediaProjectionManager) getSystemService(MEDIA_PROJECTION_SERVICE);
        startActivityForResult(manager.createScreenCaptureIntent(), OWT_REQUEST_CODE);
    } else {
        executor.execute(() -> {
            if (screenPublication != null) {
                screenPublication.stop();
                screenPublication = null;
            }
        });
        middleBtn.setEnabled(true);
        middleBtn.setTextColor(Color.WHITE);
        middleBtn.setText(R.string.share_screen);
    }
}
 
Example #14
Source File: ScreenCaptureFragment.java    From media-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Activity activity = getActivity();
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    mScreenDensity = metrics.densityDpi;
    mMediaProjectionManager = (MediaProjectionManager)
            activity.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
}
 
Example #15
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 #16
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 #17
Source File: ScreenRecordHelper.java    From android-openGL-canvas with Apache License 2.0 5 votes vote down vote up
public void init(Activity activity, GLTexture glTexture) {
    mActivity = activity;
    mSurface = new Surface(glTexture.getSurfaceTexture());
    mRawTexture = glTexture.getRawTexture();
    mMediaProjectionManager = (MediaProjectionManager) activity.
            getSystemService(Context.MEDIA_PROJECTION_SERVICE);

    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    mScreenDensity = metrics.densityDpi;
}
 
Example #18
Source File: ScreenRecorderService.java    From ScreenRecordingSample with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
	super.onCreate();
	if (DEBUG) Log.v(TAG, "onCreate:");
	if (BuildCheck.isLollipop())
		mMediaProjectionManager = (MediaProjectionManager)getSystemService(Context.MEDIA_PROJECTION_SERVICE);
	mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
	showNotification(TAG);
}
 
Example #19
Source File: MediaProjectionActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

    MediaProjectionManager manager = (MediaProjectionManager) getSystemService(Service.MEDIA_PROJECTION_SERVICE);
    if (manager != null) {
        startActivityForResult(manager.createScreenCaptureIntent(), REQUEST_CAPTURE);
    }
}
 
Example #20
Source File: ScreenCastVideoEncoder.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
public ScreenCastVideoEncoder(Context context) {
        mContext = context;
        mVideoQuality = new VideoQuality("video/avc");

        DisplayMetrics metrics = context.getResources().getDisplayMetrics();
//        mVideoQuality.setVideoWidth(metrics.widthPixels / 4);
//        mVideoQuality.setVideoHeight(metrics.heightPixels / 4);
        mVideoQuality.setVideoWidth(360);
        mVideoQuality.setVideoHeight(640);

        mMediaProjectionMgr = (MediaProjectionManager) context.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
    }
 
Example #21
Source File: ScreenCaptureFragment.java    From android-ScreenCapture with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Activity activity = getActivity();
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    mScreenDensity = metrics.densityDpi;
    mMediaProjectionManager = (MediaProjectionManager)
            activity.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
}
 
Example #22
Source File: ScreenshotActivity.java    From RelaxFinger with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void takeScreenshot() {
    MediaProjectionManager mediaProjectionManager = (MediaProjectionManager)
            getSystemService(Context.MEDIA_PROJECTION_SERVICE);

    sendMsg(Config.HIDE_BALL, "hide", true);

    startActivityForResult(
            mediaProjectionManager.createScreenCaptureIntent(),
            REQUEST_MEDIA_PROJECTION);

    shootSound();

}
 
Example #23
Source File: PermissionReceiverActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    // ステータスバーを消す
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
    );

    mManager = (MediaProjectionManager) getSystemService(MEDIA_PROJECTION_SERVICE);
}
 
Example #24
Source File: CatVision.java    From CatVision-io-SDK-Android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void requestStart(Activity activity, int requestCode) {
	if (android.os.Build.VERSION.SDK_INT < minAPILevel) {
		Log.w(TAG, "Can't run requestStart() due to a low API level. API level 21 or higher is required.");
		return;
	} else {
		// call for the projection manager
		mProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);

		if (sCaptureThread == null) {
			// run capture handling thread
			sCaptureThread = new Thread(new Runnable() {
				public void run() {
					Looper.prepare();
					mHandler = new Handler();
					Looper.loop();
				}
			});
			sCaptureThread.start();
		}

		try {
			SeaCatClient.connect();
		} catch (IOException e) {
			Log.e(TAG, "SeaCatClient expcetion", e);
		}

		activity.startActivityForResult(mProjectionManager.createScreenCaptureIntent(), requestCode);
	}
}
 
Example #25
Source File: DisplayBase.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
public DisplayBase(Context context, boolean useOpengl) {
  this.context = context;
  if (useOpengl) {
    glInterface = new OffScreenGlThread(context);
    glInterface.init();
  }
  mediaProjectionManager =
      ((MediaProjectionManager) context.getSystemService(MEDIA_PROJECTION_SERVICE));
  this.surfaceView = null;
  videoEncoder = new VideoEncoder(this);
  microphoneManager = new MicrophoneManager(this);
  audioEncoder = new AudioEncoder(this);
  recordController = new RecordController();
}
 
Example #26
Source File: MainActivity.java    From habpanelviewer with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == Constants.REQUEST_PICK_APPLICATION && resultCode == RESULT_OK) {
        startActivity(data);
    } else if (requestCode == Constants.REQUEST_MEDIA_PROJECTION) {

        boolean allowCapture = resultCode == RESULT_OK;
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
        if (prefs.getBoolean(Constants.PREF_CAPTURE_SCREEN_ENABLED, false) != allowCapture) {
            SharedPreferences.Editor editor1 = prefs.edit();
            editor1.putBoolean(Constants.PREF_CAPTURE_SCREEN_ENABLED, allowCapture);
            editor1.apply();
        }

        if (resultCode == RESULT_OK) {
            MediaProjectionManager projectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
            MediaProjection projection = projectionManager.getMediaProjection(RESULT_OK, data);

            DisplayMetrics metrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(metrics);

            Point size = new Point();
            getWindowManager().getDefaultDisplay().getSize(size);

            if (mCapturer == null) {
                mCapturer = new ScreenCapturer(projection, size.x, size.y, metrics.densityDpi);
            }
        }
    } else if (requestCode == Constants.REQUEST_VALIDATE) {
        if (resultCode == Activity.RESULT_CANCELED) {
            UiUtil.showButtonDialog(this, null,
                    getString(R.string.prefsDisabledMissingPermissions),
                    android.R.string.ok, (dialogInterface, i) -> onStart(), -1, null);
        } else {
            onStart();
        }
    }
}
 
Example #27
Source File: SRManager.java    From VMLibrary with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化
 */
public void init(Activity activity) {
    this.activity = activity;
    projectionManager = (MediaProjectionManager) activity.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
    if (projectionManager != null && !isRunning) {
        activity.startActivityForResult(projectionManager.createScreenCaptureIntent(), SRManager.RECORD_REQUEST_CODE);
    }
}
 
Example #28
Source File: ScreenPermissionActivity.java    From pc-android-controller-android with Apache License 2.0 5 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {

//        setTheme(android.R.style.Theme_Dialog);//这个在这里设置 之后导致 的问题是 背景很黑
        super.onCreate(savedInstanceState);

        //如下代码 只是想 启动一个透明的Activity 而上一个activity又不被pause
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setDimAmount(0f);

//        requestScreenShot();

//        PermissionsChecker pc = new PermissionsChecker(this);
//        if (pc.lacksPermissions("android.permission.CAPTURE_VIDEO_OUTPUT",
//                "android.permission.CAPTURE_SECURE_VIDEO_OUTPUT")) {
//        } else {
            MediaProjectionManager mediaProjectionManager = (MediaProjectionManager)
                    getSystemService(Context.MEDIA_PROJECTION_SERVICE);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                startActivityForResult(
                        mediaProjectionManager.createScreenCaptureIntent(),
                        REQUEST_MEDIA_PROJECTION);
            }
//        }

    }
 
Example #29
Source File: ScreenRecodeService.java    From pc-android-controller-android with Apache License 2.0 5 votes vote down vote up
private void initScreenManager() {
    L.d("初始化录屏。。。");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mMediaProjectionManager = (MediaProjectionManager)
                getSystemService(Context.MEDIA_PROJECTION_SERVICE);

        mMediaProjection = mMediaProjectionManager.getMediaProjection(Activity.RESULT_OK,
                mCapturePermissionIntent);
    }
    startDisplayManager();
    new Thread(new EncoderWorker()).start();
}
 
Example #30
Source File: ToggleActivity.java    From hyperion-android-grabber with MIT License 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void requestPermission(){
    MediaProjectionManager manager = (MediaProjectionManager)
            getSystemService(Context.MEDIA_PROJECTION_SERVICE);
    if (manager != null) {
        startActivityForResult(manager.createScreenCaptureIntent(), REQUEST_MEDIA_PROJECTION);
    }
}