@intuiface/capacitor-plugin-screenshot 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
@@ -71,7 +71,7 @@ Function to take a screenshot
|
|
71
71
|
|
72
72
|
## iOS
|
73
73
|
|
74
|
-
iOS version
|
74
|
+
iOS version 13+ is supported.
|
75
75
|
|
76
76
|
Nothing more to do, it should work by calling the `getScreenshot` function.
|
77
77
|
|
@@ -85,6 +85,11 @@ To be able to take screenshot on Android, you have to declare a foreground servi
|
|
85
85
|
```xml
|
86
86
|
<service android:enabled="true" android:foregroundServiceType="mediaProjection" android:name="com.intuiface.plugins.screenshot.ScreenCaptureService" />
|
87
87
|
```
|
88
|
+
And also add permissions :
|
89
|
+
```xml
|
90
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
91
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
|
92
|
+
```
|
88
93
|
|
89
94
|
The foreground service will ask you to cast your screen and this is mandatory to take screenshot with the `MediaProjection` API.
|
90
95
|
|
package/android/build.gradle
CHANGED
@@ -11,7 +11,7 @@ buildscript {
|
|
11
11
|
mavenCentral()
|
12
12
|
}
|
13
13
|
dependencies {
|
14
|
-
classpath 'com.android.tools.build:gradle:8.
|
14
|
+
classpath 'com.android.tools.build:gradle:8.2.1'
|
15
15
|
}
|
16
16
|
}
|
17
17
|
|
@@ -19,10 +19,10 @@ apply plugin: 'com.android.library'
|
|
19
19
|
|
20
20
|
android {
|
21
21
|
namespace "com.intuiface.plugins.screenshot"
|
22
|
-
|
22
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
|
23
23
|
defaultConfig {
|
24
24
|
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
25
|
-
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion :
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
|
26
26
|
versionCode 1
|
27
27
|
versionName "1.0"
|
28
28
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
package/android/src/main/java/com/intuiface/plugins/screenshot/CapacitorScreenshotPlugin.java
CHANGED
@@ -41,9 +41,15 @@ public class CapacitorScreenshotPlugin extends Plugin {
|
|
41
41
|
private ActivityResultLauncher<Intent> mediaProjectionActivityLauncher;
|
42
42
|
|
43
43
|
private PluginCall savedCall;
|
44
|
+
private VirtualDisplay virtualDisplay;
|
45
|
+
private Handler handler;
|
44
46
|
|
45
47
|
@Override
|
46
48
|
public void load() {
|
49
|
+
HandlerThread handlerThread = new HandlerThread("ScreenshotThread");
|
50
|
+
handlerThread.start();
|
51
|
+
handler = new Handler(handlerThread.getLooper());
|
52
|
+
|
47
53
|
mediaProjectionActivityLauncher =
|
48
54
|
getActivity()
|
49
55
|
.registerForActivityResult(
|
@@ -63,9 +69,30 @@ public class CapacitorScreenshotPlugin extends Plugin {
|
|
63
69
|
|
64
70
|
@PluginMethod
|
65
71
|
public void getScreenshot(PluginCall call) {
|
66
|
-
if (mediaProjection != null) {
|
72
|
+
if (mediaProjection != null && virtualDisplay != null) {
|
67
73
|
savedCall = call;
|
68
|
-
|
74
|
+
|
75
|
+
final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
|
76
|
+
int screenWidth = metrics.widthPixels;
|
77
|
+
int screenHeight = metrics.heightPixels;
|
78
|
+
// Create an ImageReader to capture the screen content
|
79
|
+
ImageReader imageReader = ImageReader.newInstance(screenWidth, screenHeight, PixelFormat.RGBA_8888, 1);
|
80
|
+
// Handle the captured images from the ImageReader
|
81
|
+
imageReader.setOnImageAvailableListener(
|
82
|
+
reader -> {
|
83
|
+
Image image = imageReader.acquireLatestImage();
|
84
|
+
if (image != null) {
|
85
|
+
// Process the captured image
|
86
|
+
processScreenshot(image);
|
87
|
+
// Release the image resources
|
88
|
+
image.close();
|
89
|
+
}
|
90
|
+
},
|
91
|
+
handler
|
92
|
+
);
|
93
|
+
|
94
|
+
// set the new surface to get the capture
|
95
|
+
virtualDisplay.setSurface(imageReader.getSurface());
|
69
96
|
} else {
|
70
97
|
ScreenCaptureManager screenCaptureManager = new ScreenCaptureManager(getContext());
|
71
98
|
screenCaptureManager.startForeground();
|
@@ -94,47 +121,27 @@ public class CapacitorScreenshotPlugin extends Plugin {
|
|
94
121
|
}
|
95
122
|
|
96
123
|
private void startScreenshotCapture(MediaProjection mediaProjection) {
|
97
|
-
HandlerThread handlerThread = new HandlerThread("ScreenshotThread");
|
98
|
-
handlerThread.start();
|
99
|
-
|
100
124
|
final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
|
101
125
|
int screenWidth = metrics.widthPixels;
|
102
126
|
int screenHeight = metrics.heightPixels;
|
103
|
-
|
104
|
-
Handler handler = new Handler(handlerThread.getLooper());
|
105
|
-
|
106
127
|
int screenDensity = metrics.densityDpi;
|
107
128
|
|
108
129
|
// Create an ImageReader to capture the screen content
|
109
|
-
@SuppressLint("WrongConstant")
|
110
130
|
ImageReader imageReader = ImageReader.newInstance(screenWidth, screenHeight, PixelFormat.RGBA_8888, 1);
|
131
|
+
|
132
|
+
mediaProjection.registerCallback(new MediaProjection.Callback() {}, null);
|
111
133
|
// Create a VirtualDisplay using the mediaProjection and imageReader
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
// Handle the captured images from the ImageReader
|
124
|
-
imageReader.setOnImageAvailableListener(
|
125
|
-
reader -> {
|
126
|
-
Image image = imageReader.acquireLatestImage();
|
127
|
-
if (image != null) {
|
128
|
-
// Process the captured image
|
129
|
-
processScreenshot(image);
|
130
|
-
// Release the image resources
|
131
|
-
image.close();
|
132
|
-
|
133
|
-
virtualDisplay.release();
|
134
|
-
}
|
135
|
-
},
|
136
|
-
handler
|
137
|
-
);
|
134
|
+
this.virtualDisplay =
|
135
|
+
mediaProjection.createVirtualDisplay(
|
136
|
+
"ScreenCapture",
|
137
|
+
screenWidth,
|
138
|
+
screenHeight,
|
139
|
+
screenDensity,
|
140
|
+
DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
|
141
|
+
imageReader.getSurface(),
|
142
|
+
null,
|
143
|
+
handler
|
144
|
+
);
|
138
145
|
}
|
139
146
|
|
140
147
|
private void processScreenshot(Image image) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@intuiface/capacitor-plugin-screenshot",
|
3
|
-
"version": "
|
3
|
+
"version": "2.0.0",
|
4
4
|
"description": "Capacitor plugin to take screenshot for iOS and Android devices",
|
5
5
|
"main": "dist/plugin.cjs.js",
|
6
6
|
"module": "dist/esm/index.js",
|
@@ -45,14 +45,14 @@
|
|
45
45
|
"prepare": "npx shx cp -u ./.githooks/* ./.git/hooks/"
|
46
46
|
},
|
47
47
|
"devDependencies": {
|
48
|
-
"@capacitor/android": "^
|
49
|
-
"@capacitor/core": "^
|
48
|
+
"@capacitor/android": "^6.0.0",
|
49
|
+
"@capacitor/core": "^6.0.0",
|
50
50
|
"@capacitor/docgen": "^0.0.18",
|
51
|
-
"@capacitor/ios": "^
|
52
|
-
"@ionic/eslint-config": "^0.
|
51
|
+
"@capacitor/ios": "^6.0.0",
|
52
|
+
"@ionic/eslint-config": "^0.4.0",
|
53
53
|
"@ionic/prettier-config": "^1.0.1",
|
54
54
|
"@ionic/swiftlint-config": "^1.1.2",
|
55
|
-
"eslint": "^
|
55
|
+
"eslint": "^8.57.0",
|
56
56
|
"prettier": "~2.3.0",
|
57
57
|
"prettier-plugin-java": "~1.0.2",
|
58
58
|
"rimraf": "^3.0.2",
|
@@ -61,7 +61,7 @@
|
|
61
61
|
"typescript": "~4.1.5"
|
62
62
|
},
|
63
63
|
"peerDependencies": {
|
64
|
-
"@capacitor/core": "^
|
64
|
+
"@capacitor/core": "^6.0.0"
|
65
65
|
},
|
66
66
|
"prettier": "@ionic/prettier-config",
|
67
67
|
"swiftlint": "@ionic/swiftlint-config",
|