public String invokeStringMethod(String name) throws InvocationException { return invokeMethod(name, String.class); }
public <T> T invokeMethod(String name, Class<? extends T> cls) throws InvocationException { return invokeMethod(name, EMPTY_PARAMETER_TYPES, EMPTY_ARGS, cls); }
public boolean invokeBooleanMethod(String name) throws InvocationException { Boolean result = invokeMethod(name, Boolean.class); if (result == null) { throw new InvocationException("Unable to invoke method '%s' on class '%s': null returned", name, cls); } return result; }
@SuppressWarnings("unchecked") public <T> T invokeMethod(String name, Class<?>[] parameterTypes, Object[] args, Class<? extends T> cls) throws InvocationException { Object result = invokeMethod(name, parameterTypes, args); if (result != null && !cls.isInstance(result)) { throw new InvocationException("Unable to invoke method '%s' on class '%s': mismatch return type '%s'", name, cls, result.getClass()); } return (T) result; }
private static Intent makeRestartActivityTaskGuarded(ComponentName cn) throws InvocationException { try { return Intent.makeRestartActivityTask(cn); } catch (NoSuchMethodError e) { //return IntentCompat.makeRestartActivityTask(cn); Invocation invocation = Invocation.fromClass(IntentCompat.class); return (Intent) invocation.invokeMethod("makeRestartActivityTask", new Class<?>[]{ComponentName.class}, new Object[]{cn}); } }
try { Invocation apptimize = Invocation.fromClass(CLASS_APPTIMIZE); Map<String, Object> testInfoDict = apptimize.invokeMethod(METHOD_GET_TEST_INFO, Map.class); if (testInfoDict == null) { return null;
private static @Nullable AdvertisingIdClientInfo resolveAdvertisingIdClientInfo(Context context) { try { Invocation advertisingIdClient = Invocation.fromClass(CLASS_ADVERTISING_ID_CLIENT); Object infoObject = advertisingIdClient.invokeMethod(METHOD_GET_ADVERTISING_ID_INFO, new Class<?>[] { Context.class }, new Object[] { context }); if (infoObject == null) { ApptentiveLog.w("Unable to resolve advertising ID: '%s' did not return a valid value", METHOD_GET_ADVERTISING_ID_INFO); return null; } Invocation info = Invocation.fromObject(infoObject); String id = info.invokeStringMethod(METHOD_GET_ID); boolean limitAdTrackingEnabled = info.invokeBooleanMethod(METHOD_IS_LIMIT_AD_TRACKING_ENABLED); return new AdvertisingIdClientInfo(id, limitAdTrackingEnabled); } catch (Exception e) { Throwable cause = e.getCause(); if (cause != null) { if (StringUtils.equal(cause.getClass().getSimpleName(), "GooglePlayServicesNotAvailableException")) { ApptentiveLog.e(e, "Unable to resolve advertising ID: Google Play is not installed on this device"); return null; } if (StringUtils.equal(cause.getClass().getSimpleName(), "GooglePlayServicesRepairableException")) { ApptentiveLog.e(e, "Unable to resolve advertising ID: error connecting to Google Play Services"); return null; } } ApptentiveLog.e(e, "Unable to resolve advertising ID"); logException(e); return null; } }