Skip to content

Commit d7cd5b2

Browse files
authored
[MOB-8741] Direct call for media projection method (#235)
* Direct call for media projection method * Update CHANGELOG.md
1 parent 594c1b8 commit d7cd5b2

File tree

3 files changed

+9
-27
lines changed

3 files changed

+9
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Adds BugReporting.setFloatingButtonEdge API
44
* Supports starting SDK from Dart only.
5+
* Fixes an issue with Android screenshots being black on release mode on SDK v10.13.0
56

67
## v10.13.0 (2022-03-31)
78

android/src/main/java/com/instabug/instabugflutter/InstabugFlutterPlugin.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.util.Log;
1010

1111
import androidx.annotation.NonNull;
12+
import androidx.annotation.VisibleForTesting;
1213

1314
import com.instabug.apm.APM;
1415
import com.instabug.apm.model.ExecutionTrace;
@@ -165,7 +166,7 @@ public void startWithToken(String token, ArrayList<String> invocationEvents) {
165166
.setInvocationEvents(invocationEventsArray)
166167
.build();
167168

168-
enableScreenShotByMediaProjection();
169+
enableScreenShotByMediaProjection(true);
169170
}
170171

171172
/**
@@ -429,20 +430,9 @@ public void setValue(String value, String forStringWithKey) {
429430
/**
430431
* Enables taking screenshots by media projection.
431432
*/
432-
private void enableScreenShotByMediaProjection() {
433-
try {
434-
Method method = getMethod(Class.forName("com.instabug.bug.BugReporting"),
435-
"setScreenshotByMediaProjectionEnabled", boolean.class);
436-
if (method != null) {
437-
method.invoke(null, true);
438-
}
439-
} catch (ClassNotFoundException e) {
440-
e.printStackTrace();
441-
} catch (IllegalAccessException e) {
442-
e.printStackTrace();
443-
} catch (InvocationTargetException e) {
444-
e.printStackTrace();
445-
}
433+
@VisibleForTesting
434+
public static void enableScreenShotByMediaProjection(boolean isScreenshotByMediaProjectionEnabled) {
435+
BugReporting.setScreenshotByMediaProjectionEnabled(isScreenshotByMediaProjectionEnabled);
446436
}
447437

448438
/**

example/android/app/src/androidTest/java/com/example/InstabugSample/InvokeInstabugUITest.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import static androidx.test.espresso.matcher.ViewMatchers.withResourceName;
1717
import static androidx.test.espresso.matcher.ViewMatchers.withText;
1818

19+
import com.instabug.instabugflutter.InstabugFlutterPlugin;
20+
1921
@RunWith(AndroidJUnit4.class)
2022
public class InvokeInstabugUITest {
2123

@@ -37,18 +39,7 @@ public void ensureInstabugInvocati1on() throws InterruptedException {
3739
}
3840

3941
private void disableScreenShotByMediaProjection() {
40-
try {
41-
Method method = getMethod(Class.forName("com.instabug.bug.BugReporting"), "setScreenshotByMediaProjectionEnabled", boolean.class);
42-
if (method != null) {
43-
method.invoke(null, false);
44-
}
45-
} catch (ClassNotFoundException e) {
46-
e.printStackTrace();
47-
} catch (IllegalAccessException e) {
48-
e.printStackTrace();
49-
} catch (InvocationTargetException e) {
50-
e.printStackTrace();
51-
}
42+
InstabugFlutterPlugin.enableScreenShotByMediaProjection(false);
5243
}
5344

5445
public static Method getMethod(Class clazz, String methodName, Class... parameterType) {

0 commit comments

Comments
 (0)