16
16
import com .instabug .library .logging .InstabugLog ;
17
17
import com .instabug .library .ui .onboarding .WelcomeMessage ;
18
18
19
+ import java .lang .reflect .InvocationTargetException ;
19
20
import java .lang .reflect .Method ;
20
21
import java .util .ArrayList ;
21
22
import java .util .HashMap ;
@@ -98,6 +99,7 @@ public void start(Application application, String token, ArrayList<String> invoc
98
99
invocationEventsArray [i ] = ArgsRegistry .getDeserializedValue (key , InstabugInvocationEvent .class );
99
100
}
100
101
new Instabug .Builder (application , token ).setInvocationEvents (invocationEventsArray ).build ();
102
+ enableScreenShotByMediaProjection ();
101
103
}
102
104
103
105
@@ -328,7 +330,6 @@ public void logUserEventWithName(String name) {
328
330
Instabug .logUserEvent (name );
329
331
}
330
332
331
-
332
333
/**
333
334
* Overrides any of the strings shown in the SDK with custom ones.
334
335
* @param value String value to override the default one.
@@ -338,5 +339,51 @@ public void setValue(String value, String forStringWithKey) {
338
339
InstabugCustomTextPlaceHolder .Key key = ArgsRegistry .getDeserializedValue (forStringWithKey , InstabugCustomTextPlaceHolder .Key .class );
339
340
placeHolder .set (key , value );
340
341
Instabug .setCustomTextPlaceHolders (placeHolder );
342
+ }
343
+
344
+ /**
345
+ * Enables taking screenshots by media projection.
346
+ */
347
+ private void enableScreenShotByMediaProjection () {
348
+ try {
349
+ Method method = getMethod (Class .forName ("com.instabug.bug.BugReporting" ), "setScreenshotByMediaProjectionEnabled" , boolean .class );
350
+ if (method != null ) {
351
+ method .invoke (null , true );
352
+ }
353
+ } catch (ClassNotFoundException e ) {
354
+ e .printStackTrace ();
355
+ } catch (IllegalAccessException e ) {
356
+ e .printStackTrace ();
357
+ } catch (InvocationTargetException e ) {
358
+ e .printStackTrace ();
359
+ }
360
+ }
361
+
362
+ /**
363
+ * Gets the private method that matches the class, method name and parameter types given and making it accessible.
364
+ * For private use only.
365
+ * @param clazz the class the method is in
366
+ * @param methodName the method name
367
+ * @param parameterType list of the parameter types of the method
368
+ * @return the method that matches the class, method name and param types given
369
+ */
370
+ public static Method getMethod (Class clazz , String methodName , Class ... parameterType ) {
371
+ final Method [] methods = clazz .getDeclaredMethods ();
372
+ for (Method method : methods ) {
373
+ if (method .getName ().equals (methodName ) && method .getParameterTypes ().length ==
374
+ parameterType .length ) {
375
+ for (int i = 0 ; i < parameterType .length ; i ++) {
376
+ if (method .getParameterTypes ()[i ] == parameterType [i ]) {
377
+ if (i == method .getParameterTypes ().length - 1 ) {
378
+ method .setAccessible (true );
379
+ return method ;
380
+ }
381
+ } else {
382
+ break ;
383
+ }
384
+ }
385
+ }
386
+ }
387
+ return null ;
341
388
}
342
389
}
0 commit comments