4package org.qtproject.qt.android.multimedia;
6import android.app.Activity;
7import android.content.ComponentName;
8import android.content.Context;
9import android.content.Intent;
10import android.content.ServiceConnection;
11import android.media.projection.MediaProjectionManager;
12import android.os.Build;
13import android.os.IBinder;
14import android.util.Log;
15import android.util.Size;
16import android.util.DisplayMetrics;
17import android.view.Display;
18import android.view.WindowManager;
19import android.view.WindowMetrics;
22class QtScreenGrabber {
25 private QtScreenCaptureService mService =
null;
26 private final Context m_activity;
27 static final String DATA =
"data";
28 static final String HEIGHT =
"height";
29 static final String ID =
"id";
30 static final String RESULT_CODE =
"resultCode";
31 static final String WIDTH =
"width";
32 private static final String QtTAG =
"QtScreenGrabber";
34 private ServiceConnection mConnection =
new ServiceConnection() {
37 synchronized (mServiceLock) {
38 QtScreenCaptureService.ScreenCaptureBinder binder =
39 (QtScreenCaptureService.ScreenCaptureBinder) service;
40 mService = binder.getService();
41 mServiceLock.notify();
47 synchronized (mServiceLock) {
53 QtScreenGrabber(Activity activity,
int requestCode) {
55 MediaProjectionManager mgr = (MediaProjectionManager)
activity.getSystemService(
Context.MEDIA_PROJECTION_SERVICE);
56 activity.startActivityForResult(mgr.createScreenCaptureIntent(), requestCode);
59 public static Size getScreenCaptureSize(Activity activity) {
60 WindowManager windowManager = (WindowManager)
activity.getSystemService(
Context.WINDOW_SERVICE);
61 if (windowManager ==
null) {
62 Log.w(QtTAG,
"WindowManager is null. Invalid screen size");
63 return new Size(0, 0);
66 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
67 WindowMetrics
metrics = windowManager.getCurrentWindowMetrics();
71 DisplayMetrics
metrics =
new DisplayMetrics();
77 public boolean startScreenCaptureService(
int resultCode,
long id,
int width,
int height, Intent
data) {
79 Intent serviceIntent =
new Intent(m_activity, QtScreenCaptureService.class);
80 serviceIntent.putExtra(RESULT_CODE, resultCode);
81 serviceIntent.putExtra(DATA,
data);
82 serviceIntent.putExtra(ID,
id);
83 serviceIntent.putExtra(WIDTH,
width);
84 serviceIntent.putExtra(HEIGHT,
height);
85 m_activity.bindService(serviceIntent, mConnection,
Context.BIND_AUTO_CREATE);
86 m_activity.startService(serviceIntent);
87 }
catch (Exception e) {
88 Log.w(QtTAG,
"Cannot start QtScreenCaptureService: " + e);
95 public boolean stopScreenCaptureService() {
97 Intent serviceIntent =
new Intent(m_activity, QtScreenCaptureService.class);
98 synchronized (mServiceLock) {
102 mServiceLock.wait(1000);
104 if (mService !=
null)
105 mService.stopScreenCapture();
106 m_activity.unbindService(mConnection);
108 m_activity.stopService(serviceIntent);
109 }
catch (Exception e) {
110 Log.w(QtTAG,
"Cannot stop QtScreenCaptureService: " + e);
struct wl_display * display
Q_CORE_EXPORT QtJniTypes::Activity activity()
static void onServiceConnected(JNIEnv *, jclass, jlong id, jstring name, jobject service)
static void onServiceDisconnected(JNIEnv *, jclass, jlong id, jstring name)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
[0]
GLsizei GLenum const void GLuint GLsizei GLfloat * metrics
EGLImageKHR EGLint * name