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;
21class QtScreenGrabber {
24 private QtScreenCaptureService mService =
null;
25 private final Context m_activity;
26 static final String DATA =
"data";
27 static final String HEIGHT =
"height";
28 static final String ID =
"id";
29 static final String RESULT_CODE =
"resultCode";
30 static final String WIDTH =
"width";
31 private static final String QtTAG =
"QtScreenGrabber";
33 private ServiceConnection mConnection =
new ServiceConnection() {
36 synchronized (mServiceLock) {
37 QtScreenCaptureService.ScreenCaptureBinder binder =
38 (QtScreenCaptureService.ScreenCaptureBinder) service;
39 mService = binder.getService();
40 mServiceLock.notify();
46 synchronized (mServiceLock) {
52 QtScreenGrabber(Activity activity,
int requestCode) {
54 MediaProjectionManager mgr = (MediaProjectionManager)
activity.getSystemService(
Context.MEDIA_PROJECTION_SERVICE);
55 activity.startActivityForResult(mgr.createScreenCaptureIntent(), requestCode);
58 public static Size getScreenCaptureSize(Activity activity) {
59 WindowManager windowManager = (WindowManager)
activity.getSystemService(
Context.WINDOW_SERVICE);
60 if (windowManager ==
null) {
61 Log.w(QtTAG,
"WindowManager is null. Invalid screen size");
62 return new Size(0, 0);
65 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
66 WindowMetrics
metrics = windowManager.getCurrentWindowMetrics();
70 DisplayMetrics
metrics =
new DisplayMetrics();
76 public boolean startScreenCaptureService(
int resultCode,
long id,
int width,
int height, Intent
data) {
78 Intent serviceIntent =
new Intent(m_activity, QtScreenCaptureService.class);
79 serviceIntent.putExtra(RESULT_CODE, resultCode);
80 serviceIntent.putExtra(DATA,
data);
81 serviceIntent.putExtra(ID,
id);
82 serviceIntent.putExtra(WIDTH,
width);
83 serviceIntent.putExtra(HEIGHT,
height);
84 m_activity.bindService(serviceIntent, mConnection,
Context.BIND_AUTO_CREATE);
85 m_activity.startService(serviceIntent);
86 }
catch (Exception e) {
87 Log.w(QtTAG,
"Cannot start QtScreenCaptureService: " + e);
94 public boolean stopScreenCaptureService() {
96 Intent serviceIntent =
new Intent(m_activity, QtScreenCaptureService.class);
97 synchronized (mServiceLock) {
101 mServiceLock.wait(1000);
103 if (mService !=
null)
104 mService.stopScreenCapture();
105 m_activity.unbindService(mConnection);
107 m_activity.stopService(serviceIntent);
108 }
catch (Exception e) {
109 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